Skip to content

[html] codegen ignores schema on a separate path #4768

@DavidBiesack

Description

@DavidBiesack
Description

When parsing a swagger.yaml file which contains external schema via $ref, swagger-codegen only looks at the last element of the schema path. Thus, for the below definition only the schema for a at http://localhost/swagger-codegen-apidoc/schemas/a/schema.json is processed. The schema for b at http://localhost/swagger-codegen-apidoc/schemas/b/schema.json is ignored. Using -l html, the schema links for member b resolves to a model named schema which links to the schema for http://localhost/swagger-codegen-apidoc/schemas/a/schema.json. The name schema appears to be derived from the last path element schema.json and dropping everything after the first ..

Our real use case depends on the ability to distinguish models by path, as we use
the url pattern
http://www.example.com/schema/{{media-type-name}}/v1/schema.json
for schema for many different application/vnd.sas.* media types
as these media types / schema are shared across many APIs. (We do not
embed them in each swagger.yaml file but use $ref to reference the shared schema files.)

For example with generate -l html, the output looks like

model - A sample model
A model that which represents a thing resource. contains members a, b, and a version.
a (optional)
schema Model A
b (optional)
schema Model B
version (optional)
String semantic version

swagger-codegen also can't distinguish resources such as
http://localhost/swagger-codegen-apidoc/schemas/application/vnd.sas.a.json
and http://localhost/swagger-codegen-apidoc/schemas/application/vnd.sas.b.json.
swagger-codegen appear to strip off everything after the first . in the last path element,
and thus both of these resolve to the model name vnd.

The only way to make this work is to contort the resource names:
http://localhost/swagger-codegen-apidoc/schemas/application/vnd-sas-a.json
http://localhost/swagger-codegen-apidoc/schemas/application/vnd-sas-b.json
We would prefer to not do this just because of the tooling.

swagger-ui also has similar problems with these schema resources.

Swagger-codegen version

2.2.2-SNAPSHOT

Swagger declaration file content or url

swagger.yaml :

swagger: "2.0"
info:
  version: "1"
  title: A Sample API
  description: swagger tools ignore schema with different paths

basePath: '/sample'
paths:
  /thing:
    get:
      summary: Return a thing
      description: Return the JSON representation of a `thing` resource.
      produces:
        - application/json
      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/model'
definitions:
  model:
    title: A sample model
    description: A model that which represents a `thing` resource. contains members a, b, and a version.
    properties:
       a:
          description: Model **A**
          type: object
          $ref: http://localhost/swagger-codegen-apidoc/schemas/a/schema.json
       b:
          description: Model **B**
          type: object
          $ref: http://localhost/swagger-codegen-apidoc/schemas/b/schema.json
       version:
          description: "[semantic version](http://semver.org/)"
          type: string

schemas/a/schema.json :

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id" : "http://localhost/reference/schema/a/schema.json",
    "title": "Link",
    "description": "Model A",
    "properties": {
        "foo": {
            "type": "string",
            "description": "some data...."
        }
    }
}

schemas/b/schema.json :

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id" : "http://localhost/reference/schema/a/schema.json",
    "title": "Link",
    "description": "Model B",
    "properties": {
        "bar": {
            "type": "string",
            "description": "some other data...."
        }
    }
}

Command line used for generation
java -jar  ~/dev/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
  generate -i http://localhost/swagger-codegen-apidoc/swagger.yaml -l html  -o samples/apidoc
Steps to reproduce

Configure localhost so that the directory containing the files is available via the context 'swagger-codegen-apidoc'

swagger.yaml
schemas/a/schema.json
schemas/b/schema.json
Related issues
Suggest a Fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions