Skip to content

code gen (javascript) fails if schema uses items with array value #4414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Shulamite opened this issue Dec 16, 2016 · 1 comment
Closed

code gen (javascript) fails if schema uses items with array value #4414

Shulamite opened this issue Dec 16, 2016 · 1 comment

Comments

@Shulamite
Copy link

Shulamite commented Dec 16, 2016

Description

Code gen doesn't seem to understand the lines array even though the swagger editor takes the above swagger as valid.

The error messages is:
Unable to build target: Could not process model 'order'.Please make sure that your schema is correct!
Details:
Object
code: 1
type: "error"
message: "Unable to build target: Could not process model 'order'.Please make sure that your schema is correct!"

Swagger-codegen version

Used the javascript client gen from swagger editor ui: http://editor.swagger.io/#/

Swagger declaration file content or url
swagger: '2.0'
info:
title: metadata for order
version: 11.1.13
description: metadata for order
paths:
'/api/version/orders/{id}':
parameters:
- name: id
in: path
description: order id
type: integer
required: true
get:
produces:
- application/vnd.oracle.resource+json;type=singular
consumes:
- application/x-www-form-urlencoded
summary: Retrieve an order instance
description: Retrieve an order instance
operationId: getOrder
responses:
default:
schema:
$ref: '#/definitions/order'
description: return order successfully
patch:
produces:
- application/vnd.oracle.resource+json;type=singular
consumes:
- application/vnd.oracle.resource+json;type=singular
summary: Update an order instance
description: Update an order instance
operationId: updateOrder
responses:
default:
schema:
$ref: '#/definitions/order'
description: order updated successfully
parameters:
- name: request
description: >-
The following table describes the body parameters in the request for
this task.
schema:
$ref: '#/definitions/order'
in: body
definitions:
order:
title: Order
description: A purchase order object
properties:
id:
type: integer
title: order id
description: identifier of an order
description:
type: string
title: Description
description: description of the order
lines:
type: array
items:
- type: string
- type: number    ```

##### Command line used for generation

Used the link from swagger editor

##### Steps to reproduce

1. go to swagger editor
2. paste the example swagger
3. click on Generate Client/javascript

##### Related issues
https://github.com/swagger-api/swagger-editor/issues/1136

##### Suggest a Fix
It should handle the array value for "items" based on JSON schema spec.

The swagger spec says:
The following properties are taken from the JSON Schema definition but their definitions were adjusted to the Swagger Specification. Their definition is the same as the one from JSON Schema, only where the original definition references the JSON Schema definition, the Schema Object definition is used instead.
items

The swagger meta schema defines "items" as either a schema or an array of schema:
        "items": {
          "anyOf": [
            {
              "$ref": "#/definitions/schema"
            },
            {
              "type": "array",
              "minItems": 1,
              "items": {
                "$ref": "#/definitions/schema"
              }
            }
          ],
          "default": {
            
          }
        }
@webron
Copy link
Contributor

webron commented Dec 18, 2016

As mentioned in the linked topic, that's not a valid schema as the spec doesn't support multi types.

@webron webron closed this as completed Dec 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants