OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.96k stars 6.59k forks source link

attribute components.schemas.test.default is not of type `string` #1324

Open aDuffit opened 6 years ago

aDuffit commented 6 years ago
Description

The generator throw "attribute components.schemas.test.default is not of type string" when property is of type array and default value is array.

openapi-generator version

3.3.1

OpenAPI declaration file content or url
"schema": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    },
                    "default": [
                        {
                            "id": "asc"
                        }
                    ]
                }
ceefour commented 5 years ago

I got hit by this too today. Additional info, still happened on 4.0.0-beta.

Bug Report Checklist

Description

openapi-generator is unable to generate API client when query parameter's schema.default is array because it expects string.

$ openapi-generator generate -i E:\tmp\lovia-heartenly-profile-4.0-swagger.yaml -g typescript-fetch -o swagger
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 5, Warning count: 3
Errors:
        -attribute paths.'/compactProfiles/findAllByAreas'(get).parameters.[profileVisibilities].schemas.default is not of type `string`
        -attribute paths.'/compactProfiles/findAllFeatured'(get).responses.200.content.examples.Example name gender=M doesn't adhere to regular expression ^[a-zA-Z0-9\.\-_]+$
        -attribute paths.'/compactProfiles/findAllByReligions'(get).parameters.[profileVisibilities].schemas.default is not of type `string`
        -attribute paths.'/compactProfiles/findAllByCultures'(get).parameters.[profileVisibilities].schemas.default is not of type `string`
        -attribute paths.'/compactProfiles/findAllFeatured'(get).responses.200.content.examples.Example name gender=F doesn't adhere to regular expression ^[a-zA-Z0-9\.\-_]+$
Warnings:
        -Unused model: DataFoundResponse
        -Unused model: HousingTenure
        -Unused model: User

        at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:578)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:353)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:62)
openapi-generator version

0.0.7-4.0.0-beta

OpenAPI declaration file content or url
  /compactProfiles/findAllByAreas:
    get:
      tags:
        - compactProfiles
      summary: List users by area(s)
      description: Filtered by areas, genders, and profile visibilities.
        Enables [HRT-33](https://samaragroup.atlassian.net/browse/HRT-33) and [HRT-37](https://samaragroup.atlassian.net/browse/HRT-71).
        Implements [HRT-71](https://samaragroup.atlassian.net/browse/HRT-71).
      parameters:
      - name: profileVisibilities
        in: query
        required: false
        schema:
          type: array
          items:
            $ref: '#/components/schemas/ProfileVisibility'
          default:
            - P
        style: form
        description: Only match given profile visibilities
      - name: areaIds
        description: Only match given GeoPlace IDs
        in: query
        required: true
        schema:
          type: array
          items:
            type: integer
            format: int32
        style: form
      - name: genders
        in: query
        required: false
        schema:
          type: array
          items:
            $ref: '#/components/schemas/Gender'
        style: form
        description: Only match given gender(s)
      - name: size
        in: query
        required: false
        schema:
          type: integer
        description: Result page size
      - name: after
        in: query
        required: false
        schema:
          type: string
        description: Pagination cursor
      responses:
        200:
          description: Return user details filtered by area, gender, and/or profile visibility
          content:
            application/json:
              schema:
                required:
                  - page
                  - _embedded
                properties:
                  page:
                    type: object
                    properties:
                      size:
                        type: integer
                      hasNextPage:
                        type: boolean
                      nextCursor:
                        type: string
                  _embedded:
                    properties:
                      compactProfiles:
                        type: array
                        items:
                          $ref: '#/components/schemas/CompactProfile'
              examples:
                data:
                  value:
                    page:
                      size: 2
                      hasNextPage: true
                      nextCursor: '2018-09-17T11:18:16.880Z'
                    _embedded:
                      compactProfiles:
                        - id: 102430
                          addressDisplayName: 'Kabupaten Bandung, Jawa Barat, Republic of Indonesia'
                          hometownDisplayName: null
                          gender: M
                          modificationTime: '2018-09-22T18:35:52.569Z'
                          photoId: aa2f42a1142a8c4ec8f47609
                          photoKey: user/profile/aa/2f/42/a1/natesin4-aa2f42a1142a8c4ec8f47609.jpeg
                          slug: natesin4
                          relationship: S
                          age: 22
                        - id: 100669
                          addressDisplayName: 'Kabupaten Bandung, Jawa Barat, Republic of Indonesia'
                          hometownDisplayName: null
                          gender: M
                          modificationTime: '2018-09-17T11:18:16.880Z'
                          photoId: aa2f42a1142a8c4ec8f47607
                          photoKey: user/profile/aa/2f/42/a1/ade_satrio-aa2f42a1142a8c4ec8f47607.jpeg
                          slug: ade_satrio
                          relationship: S
                          age: 21
        403:
          description: Access denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                error:
                  $ref: '#/components/examples/error403'
        500:
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                error:
                  $ref: '#/components/examples/error500'
Command line used for generation
openapi-generator generate -i E:\tmp\lovia-heartenly-profile-4.0-swagger.yaml -g typescript-fetch -o swagger
ceefour commented 5 years ago

@aDuffit please edit the issue title and prepend it with [BUG] to hopefully get better attention.

zquintana commented 4 years ago

I just hit this today too. Anyone know of a fix?

sharathkolibyle commented 4 years ago

Hi , Anyone have any idea on how to tackle this ?

vithu30 commented 3 years ago

Any update on this issue?

bezrukavyy commented 3 years ago

Have the same issue - V5.1 of the generator.

RagaviVaratharaj commented 3 years ago

Hi Team, I am also facing this issue. Any update on this issue

vpolimenov commented 3 years ago

Is this being looked at?

mcgorias commented 2 years ago

Hi,

The error message is a bit misleading

[...]
components:
  schemas:
    testing: 
      properties:
        id:
          type: 
            - string

returns

Errors:
        -attribute components.schemas.testing.type is not of type `string`

But the message should have been

Errors:
        -attribute components.schemas.testing.properties.id.type is not of type `string`
                                              ^^^^^^^^^^^^^
SGFGOV commented 1 year ago

I think this error still exists. I get this warning attribute components.schemas.Rating.feedback_id is not of type schema when in try to run openapi-generator-cli validate -i ./core.yaml -i logistics.yaml -i retail-hyperlocal.yaml based on the ONDC Spec

please let me know if I'm doing something that I shouldn't be doing

HCrane commented 1 year ago

Bump as error still exists.

xegulon commented 1 year ago

Bump as error still exists!

Was trying to use it with: https://docs.nestjs.com/openapi/types-and-parameters#oneof-anyof-allof

AndreiLucaci commented 11 months ago

So, any fix on this issue?

It still exists.

I'm using oneOf

Here's the base link https://docs.nestjs.com/openapi/types-and-parameters#oneof-anyof-allof

ftvrdon commented 6 months ago

this probably won't help too many people but I've found that I was incorrectly combining type and $ref in my spec. sadly, the exception message didn't help much finding the place where I made a mistake


 application/hal+json:
   schema:
     type:
       $ref: '#/components/schemas/MyType'