Openapi-generator: [C#] Missing Models for Map types and incomplete types for Api Endpoints

Created on 8 Jun 2018  路  10Comments  路  Source: OpenAPITools/openapi-generator

Description

With the following valid spec

  • The map models are not generated and the Api is having a wrong type for the response associated with map.
  • When a map is part of an object the model is generated correctly with the map inside the object.
    When a model type is a map, there is incorrect generation of code either as an inline model or as a map when referred from another model.

  • General issues with inline models always being reported as objects

openapi-generator version


3.0.0

OpenAPI declaration file content or url
---
# This is a sample Swagger spec

swagger: "2.0"
info:
  description: Application Description
  version: 1.0.0
  title: Application

host: 0.0.0.0:8080
basePath: /api/v1.0
schemes:
- http

tags:
- name: ApplicationResources
  x-displayName: "ApplicationResources"
  description: |
    "Application Resources."

- name : ApplicationLifeCycle
  x-displayName : "ApplicationLifeCycle"
  description : |
    "Application Lifecycle."

- name: ApplicationTestConfiguration
  x-displayName : "ApplicationTestConfiguration"
  description : |
    "Application Test Configuration"

- name: ApplicationEndpointTest
  x-displayName: "ApplicationEndpointTest"
  description: |
    "Application Endpoint Test"

paths:
  /default/Resources/{id}: 
    post:
      tags:
      - ApplicationResources      
      operationId: resourceStatusSet
      consumes:
      - application/json
      produces:
      - application/json
      parameters:
      - name: "exclusive"
        in: "query"
        type: "boolean"
        default: false
      - name: id
        in: "path"
        required: true
        type: integer
        format: int32
      - name: "body"
        in: "body"
        schema:
          $ref: "#/definitions/ResourceRequest"
      responses:
        200:
          description: ""
          schema:
            $ref: "#/definitions/ResourceOperationsStatus"
        404:
          description: ""
          schema:
            $ref: "#/definitions/ErrorSts"
    get:
      tags:
      - ApplicationResources
      operationId: resourceStatusGet
      produces:
      - application/json
      parameters:
      - name: id
        in: path
        description: "Id of the Resource"
        required: true
        type: integer
        format: int32
      responses:
        200:
          description: ""
          schema:
            $ref: "#/definitions/Resource"
        404:
          description: ""        
          schema:
            $ref: "#/definitions/ErrorSts"  

  /default/ApiTestSetup: 
    post: 
      tags: 
      - ApplicationTestConfiguration     
      operationId : apiTestConfigurationSet
      consumes:
      - application/json
      parameters : 
      - name : "body"
        in : "body"
        required: true
        schema: 
          $ref: "#/definitions/TestEndPointConfig"
      responses:
        200:
          description: "Successful response"
        400:
          description: "The request was not successfully executed." 
    get:
      tags:
      - ApplicationTestConfiguration
      operationId: apiTestConfigurationGet
      produces:
      - application/json      
      responses:
        200:
          description: "Successful response"
          schema: 
            $ref: "#/definitions/TestEndPointConfig"          
        400:
          description: "The request was not successfully executed."           


definitions:

  Options:
    type: "object"
    properties:
      Config:
        type: "object"
        additionalProperties:
          type: "string"

  Resource:
    required:
      - id
    type: object  
    properties:
      id:
        type: integer
        format: int32
      name:
        type: string 
      type:
        type: string
      options:
        $ref: "#/definitions/Options" 

  ResourceOperations:
    type: "object"
    additionalProperties:
      type: "string"

  ResourceOperationsStatus:
    type: "object"
    additionalProperties:
      type: "string"

  ResourceRequest:
    allOf:
    - $ref: "#/definitions/Resource"
    - type: "object"
      required:
      - handle
      properties:
        handle:
          type : "string"
          x-nullable: false
        requestCode:
          type: integer
          format: int32
        operations:
          $ref: "#/definitions/ResourceOperations"
        payload:
          type: array
          items:
            type: integer
            format: int32    
        args:
          type: "array"
          items:
            type: "string"  

  ErrorSts:
    required:
      - code
    type : object   
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string  

  TestEndPointConfig : 
    type : "object"
    additionalProperties :
      type: "string"      
Command line used for generation


java -jar ~/dev/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ./Cta.yaml -o ./genserver -l aspnetcore --additional-properties packageName=Cta

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

Is the Map support broken in C#

C-Sharp Bug

All 10 comments

seems broken on golang as well.
Strange it is not working on Qt5 as well.
For Qt5 I have added nested arrays and nested map support before and now it is not working.

It was reported to be broken in java as well, if I understood #191 correctly.

For golang for example
java -jar /home/dev/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ./api.yaml -o ./gengo-server -g go-server --additional-properties packageName=cta --additional-properties hideGenerationTimestamp=true

This spec creates a valid model with a map

  Options:
    type: "object"
    properties:
      Config:
        description: "List of configuration options"
        type: "object"
        additionalProperties:
          type: "string"

This one when referenced inside another model creates an error

  ResourceOperations:
    description: "An object describing the operations"
    type: "object"
    additionalProperties:
      type: "string"

I have not even tried nested containers as yet. Does not look good for now.

this is broken also in typescript-angular code generator

UPDATE: I'm able to identify the issue and working on a fix (which requires changing how Map schema is handled in many places). I'm aiming for a fix ready for test by tomorrow.

(codegen also has the same issue so it's not a bug we introduced to openapi generator)

UPDATE: I'm hoping to release the fix tomorrow (Wed). Sorry for the delay.

Filed https://github.com/OpenAPITools/openapi-generator/pull/360 to fix it. Please give it a try when you've time.

```C#
[SwaggerResponse(statusCode: 200, type: typeof(Dictionary), description: "Successful response")]
public virtual IActionResult ApiTestConfigurationGet()


Severity Code Description Project File Line Suppression State
Error CS0305 Using the generic type 'Dictionary'
requires 2 type arguments
```
I merged the changes on my fork but it is not working.

Fixed with #360

Was this page helpful?
0 / 5 - 0 ratings