Skip to content

Commit

Permalink
Merge pull request #405 from swagger-api/issue#404
Browse files Browse the repository at this point in the history
fix and test for issue #404 NullExample
  • Loading branch information
gracekarina authored Aug 25, 2021
2 parents d8f6b55 + 3c6b427 commit d4f0ecf
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
<properties>
<maven-javadoc-version>3.0.1</maven-javadoc-version>
<swagger-core-version>2.1.10</swagger-core-version>
<swagger-parser-version>2.0.27</swagger-parser-version>
<swagger-parser-version>2.0.28-SNAPSHOT</swagger-parser-version>
<jackson.version>2.12.1</jackson.version>
<jetty-version>9.4.39.v20210325</jetty-version>
<jersey2-version>2.32</jersey2-version>
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/io/swagger/oas/test/examples/ExampleBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public class ExampleBuilderTest {
Yaml.mapper().registerModule(simpleModule);
}

@Test
public void testIssue404_NullExample(){
ParseOptions options = new ParseOptions();
options.setResolveFully(true);

OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/swagger/sampleNull.json", null, options);
Example example = ExampleBuilder.fromSchema(openAPI.getComponents().getSchemas().get("Bundle"), openAPI.getComponents().getSchemas());
String json = Json.pretty(example);
assertEquals(json,"{\n" +
" \"_id\" : \"string\",\n" +
" \"project_id\" : \"string\",\n" +
" \"href\" : \"string\",\n" +
" \"name\" : \"string\"\n" +
"}");
}

@Test
public void testAnonymousModel(){
ParseOptions options = new ParseOptions();
Expand Down
175 changes: 175 additions & 0 deletions src/test/swagger/sampleNull.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
"swagger": "2.0",
"info": {
"description": "Blah",
"version": "1.0.0",
"title": "Blah",
"termsOfService": "",
"contact": {
"email": ""
},
"license": {
"name": "",
"url": "http://unlicense.org"
}
},
"basePath": "/rest",
"tags": [
],
"paths": {
"/v1/tx/packages/{package_id}": {
"get": {
"tags": [
"Packages"
],
"summary": "Get a package",
"description": "Get details about a package",
"operationId": "getPackage",
"produces": [
"application/json;charset=utf-8"
],
"parameters": [
{
"name": "package_id",
"in": "path",
"description": "ID of the package",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Error",
"schema": {
"$ref": "#/definitions/Bundle"
}
}
}
},
"put": {
"tags": [
"Packages"
],
"summary": "Edit a package definition",
"description": "Replace package definition",
"operationId": "replacePackage",
"consumes": [
"application/json;charset=utf-8"
],
"produces": [
"application/json;charset=utf-8"
],
"parameters": [
{
"name": "package_id",
"in": "path",
"description": "ID of the package",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "body",
"description": "Package definition.",
"required": true,
"schema": {
"$ref": "#/definitions/Bundle"
}
}
],
"responses": {
"200": {
"description": "Error",
"schema": {
"$ref": "#/definitions/Bundle"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/Bundle"
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/Bundle"
}
}
}
},
"delete": {
"tags": [
"Packages"
],
"summary": "Delete a package",
"description": "Remove a package",
"operationId": "deletePackage",
"produces": [
"application/json;charset=utf-8"
],
"parameters": [
{
"name": "package_id",
"in": "path",
"description": "ID of the package",
"required": true,
"type": "string"
}
],
"responses": {
"204": {
"description": "Success"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"200": {
"description": "Error"
}
}
}
}
},
"definitions": {
"Annotation": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Annotation name"
},
"value": {
"type": "string",
"description": "Annotation value"
}
},
"description": "Resource annotation"
},
"Bundle": {
"type": "object",
"properties": {
"_id": {
"type": "string",
"description": "The id of the object"
},
"project_id": {
"type": "string",
"description": "The project id of the map or file"
},
"href": {
"type": "string",
"description": "The URI for the object"
},
"name": {
"type": "string",
"description": "Name of the package"
}
}
},
"description": "A bundle (package)"
}
}

0 comments on commit d4f0ecf

Please sign in to comment.