question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing swagger-spec copies responses.200.schema into property responses.200.responseSchema?

See original GitHub issue

Here is an example of an endpoint with the schema property being copied.

	"post": {
		"tags": [
			"users"
		],
		"consumes": [
			"application/x-www-form-urlencoded"
		],
		"produces": [
			"application/xml",
			"application/json"
		],
		"parameters": [
			{
				"name": "userId",
				"in": "path",
				"description": "the ID of the user",
				"required": true,
				"type": "string"
			},
			{
				"name": "AuthToken",
				"in": "header",
				"description": "Authentication token",
				"required": true,
				"type": "string"
			}
		],
		"responses": {
			"200": {
				"description": "Successful operation",
				"schema": {
					"$ref": "#/definitions/GameUsage"
				}
			},
			"400": {
				"description": "Invalid status value"
			}
		}
	}
}

is transformed into

"/users" : {
      "post" : {
        "tags" : [ "users" ],
        "consumes" : [ "application/x-www-form-urlencoded" ],
        "produces" : [ "application/xml", "application/json" ],
        "parameters" : [ {
          "name" : "userId",
          "in" : "path",
          "description" : "the ID of the user",
          "required" : true,
          "type" : "string"
        },
		{
          "name" : "AuthToken",
          "in" : "header",
          "description" : "Authentication token",
          "required" : true,
          "type" : "string"
        } ],
        "responses" : {
          "200" : {
            "description" : "Successful operation",
            "responseSchema" : {
              "$ref" : "#/definitions/GameUsage"
            },
            "schema" : {
              "$ref" : "#/definitions/GameUsage"
            }
          },
          "400" : {
            "description" : "Invalid status value"
          }
        }
      }
    }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
frantumacommented, Jul 19, 2018

You have two options:

  1. either use the configured mapper provided by swagger-core via io.swagger.v3.core.util.Json.mapper() (or Yaml.mapper()) and if needed customize it further e.g with SerializationFeature.INDENT_OUTPUT

  2. add the following to your mapper config: mapper.addMixIn(Response.class, ResponseSchemaMixin.class);

0reactions
gracekarinacommented, Jul 19, 2018

Glad to see your issue is solved. About the ResponseSchemaMixin, it establishes the responseSchema attribute as the schema property. This is part of a change made in core to support Model in the schema attribute which was previously a property. https://github.com/swagger-api/swagger-core/blob/1.5/modules/swagger-core/src/main/java/io/swagger/jackson/mixin/ResponseSchemaMixin.java

Read more comments on GitHub >

github_iconTop Results From Across the Web

Describing Responses - Swagger
Under responses , each response definition starts with a status code, such as 200 or 404. An operation typically returns one successful status...
Read more >
Swagger: Specify Two Responses with the Same ... - Baeldung
In this article, we'll write an API specification that allows returning two different objects for the same response code.
Read more >
Error returning boolean in Swagger-Node - Stack Overflow
This is my swagger spec. responses: '200': description: a string that represents a boolean value schema: type: string.
Read more >
Swagger2 — metosin/spec-tools 0.10.5 - cljdoc
An utility to transform Specs to Swagger2 Schemas. Spec transformations. swagger/transform converts specs into Swagger2 Schema. Transformation can be customized ...
Read more >
Create Your First OpenAPI Definition with Swagger Editor
OpenAPI definitions can be serialized in either YAML or JSON and ... default: json responses: '200': description: Success response schema: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found