OpenAPITools / OpenAPITools/openapi-generator

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

Open
#16,850 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the reported openapi-generator-cli command with the supplied spec and inspect the generated BearerToken.cs and SubObject.cs files. Confirm that model-only generation emits the invalid OpenAPIDateConverter using directive; done means generated C# models no longer reference the nonexistent Spec.Client.Client namespace and build successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.