Skip to content

Uncaught TypeError: Cannot read property '$ref' of undefined #247

@zimmem

Description

@zimmem
Description

I use swagger-codegen-cli-3.0.2 to generate html2 document. in the document , all responses schema are empty, and I got a lot of error "Uncaught TypeError: Cannot read property '$ref' of undefined" at chrome console. I inspect the schema element of Dom, and the content is like:

<div id="responses-get-200-schema-200" style="padding: 30px; border-left: 1px solid #eee; border-right: 1px solid #eee; border-bottom: 1px solid #eee;">
                                    <script>
                                      $(document).ready(function() {
                                        var schemaWrapper = {
  "description" : "successful operation",
  "content" : {
    "application/json" : {
      "schema" : {
        "$ref" : "#/components/schemas/Profile"
      }
    }
  }
};
                                        var schema = schemaWrapper.schema;
                                        if (schema.$ref != null) {
                                          schema = defsParser.$refs.get(schema.$ref);
                                        } else {
                                          schemaWrapper.definitions = Object.assign({}, defs);
                                          $RefParser.dereference(schemaWrapper).catch(function(err) {
                                            console.log(err);
                                          });
                                        }

                                        //console.log(JSON.stringify(schema));
                                        var view = new JSONSchemaView(schema, 3);
                                        $('#responses-get-200-schema-data').val(stringify(schema));
                                        var result = $('#responses-get-200-schema-200');
                                        result.empty();
                                        result.append(view.render());
                                      });
                                    </script>
                                  </div>
Swagger-codegen version

swagger-codegen-cli-3.0.2

Swagger declaration file content or url

The code snippet is :

openapi: 3.0.0
...
paths:
  '/person/{personId}/profile':
    parameters: 
      - $ref: "#/components/parameters/personIdInPath"
    get:
      tags:
        - profile
      summary: get person profile
      description: ''
      operationId: get
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Profile'
Command line used for generation

java -jar swagger-codegen-cli-3.0.2.jar generate -i openapi.yaml -l html2 -o html2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions