Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2118. Fix issue with assigning empty model name when title empty for inline schema #2119

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/swagger-parser-v3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-project</artifactId>
<version>2.1.23-SNAPSHOT</version>
<version>2.1.22</version>
<relativePath>../..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -416,7 +417,7 @@ private static String normalize(String pathPart)
}

private String resolveModelName(String title, String key) {
if (title == null) {
if (StringUtils.isBlank(title)) {
return uniqueName(key);
} else {
return uniqueName(title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1509,4 +1509,16 @@ public void testSchemaPropertiesBeingPassedToFlattenedModel() {
assertEquals(userAddress.getWriteOnly(), Boolean.FALSE);

}

@Test(description = "https://github.com/swagger-api/swagger-parser/issues/2118")
public void testInlineSchemaWithEmptyTitle() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("issue2118/issue2118.yaml", null, options);

assertNotNull(openAPI);
assertNotNull(openAPI.getComponents().getSchemas().get("MegaPet_creator"));
assertNull(openAPI.getComponents().getSchemas().get(""));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
openapi: "3.0.0"
info:
title: API
description: API
version: 1.0.0
paths:
/pet-types:
post:
description: Creates a new pet in the store. Duplicates are allowed
operationId: addPet
requestBody:
description: Pet to add to the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/MegaPet'
responses:
'200':
description: pet response
content:
application/json:
schema:
$ref: '#/components/schemas/MegaPet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
MegaPet:
properties:
id:
type: integer
format: int64
code:
type: string
format: byte
example: MjIyMjIyMg==
additionalCode:
type: string
format: binary
example: MjIyMjIyMg==
dateOfBirth:
type: string
format: date
example: "2000-12-12"
timeOfVaccination:
type: string
format: date-time
example: 2012-01-24T15:54:14.876Z
age:
type: string
pattern: "[0-9]+"
owner:
type: object
previousOwner:
type: object
example: "prev owner"
metadata:
type: object
maxProperties: 10
additionalProperties:
type: string
maxLength: 256
creator:
title: ''
description: ''
type: object
properties:
id:
description: ''
type: string
example: 63d415e0dd0d828c3a878548
readOnly: true
email:
description: ''
type: string
example: [email protected]
readOnly: true
displayName:
description: ''
type: string
example: Boba Fett
readOnly: true