diff --git a/pom.xml b/pom.xml index 6f471ea9..e4640e3a 100644 --- a/pom.xml +++ b/pom.xml @@ -461,7 +461,7 @@ 3.0.1 2.1.10 - 2.0.27 + 2.0.28-SNAPSHOT 2.12.1 9.4.39.v20210325 2.32 diff --git a/src/test/java/io/swagger/oas/test/examples/ExampleBuilderTest.java b/src/test/java/io/swagger/oas/test/examples/ExampleBuilderTest.java index 07ac4e48..848532a5 100644 --- a/src/test/java/io/swagger/oas/test/examples/ExampleBuilderTest.java +++ b/src/test/java/io/swagger/oas/test/examples/ExampleBuilderTest.java @@ -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(); diff --git a/src/test/swagger/sampleNull.json b/src/test/swagger/sampleNull.json new file mode 100644 index 00000000..ac9e9a27 --- /dev/null +++ b/src/test/swagger/sampleNull.json @@ -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)" + } +}