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.82k stars 6.58k forks source link

[BUG] [csharp] Using --global-property models adds invalid using OpenAPIDateConverter to generated classes #16850

Open finsterdexter opened 1 year ago

finsterdexter commented 1 year ago

Bug Report Checklist

Description
openapi-generator version

7.0.1

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  description: |
    An Open API description
  title: A title
  version: 0.1.0
servers:
- url: https://example.com
tags:
- description: All authentication related routes
  name: Authentication
paths:
  /auth/oauth/v2/token:
    post:
      description: Retrieve a Bearer token from a client id / client secret
      operationId: PostAuthOauthV2Token
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/AuthenticationBody'
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BearerToken'
          description: Bearer token returned
      security: []
      servers:
      - url: https://auth.example.com
      summary: /auth/oauth/v2/token - Retrieve a Bearer token
      tags:
      - Authentication
components:
  schemas:
    AuthenticationBody:
      properties:
        client_id:
          type: string
        client_secret:
          type: string
        grant_type:
          type: string
      required:
      - client_id
      - client_secret
      - grant_type
      type: object
    BearerToken:
      properties:
        access_token:
          type: string
        token_type:
          type: string
        expires_in:
          type: integer
          nullable: true
        scope:
          type: string
          nullable: true
        nullableSubobject:
          nullable: true
          allOf: 
            - $ref: '#/components/schemas/SubObject'
      required:
      - access_token
      - token_type
      type: object
    SubObject:
      properties:
        aProp:
          type: string
          nullable: true
        bProp:
          type: integer
          nullable: true
      type: object
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http
Generation Details

openapi-generator-cli generate -g csharp --input-spec spec.yaml --output output --package-name "Spec.Client" --global-property models,modelTests=false,modelDocs=false -p targetFramework=net6.0

output of BearerToken.cs (and SubObject.cs, and every model for larger specs) contains:

using OpenAPIDateConverter = Spec.Client.Client.OpenAPIDateConverter;

That causes build errors: The type or namespace name 'Client' does not exist in the namespace 'Spec.Client' (are you missing an assembly reference?)

Steps to reproduce

Run the generator with --global-property models

janrhijn commented 12 months ago

I had the same problem. I fixed it with adding the converter as global property --global-property models,modelTests=false,modelDocs=false,supportingFiles=OpenAPIDateConverter.cs