Skip to content
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

[C#] Missing Models for Map types and incomplete types for Api Endpoints #255

Closed
etherealjoy opened this issue Jun 8, 2018 · 10 comments
Closed

Comments

@etherealjoy
Copy link
Contributor

etherealjoy commented Jun 8, 2018

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#

@etherealjoy
Copy link
Contributor Author

etherealjoy commented Jun 8, 2018

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.

@jmini
Copy link
Member

jmini commented Jun 8, 2018

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

@etherealjoy
Copy link
Contributor Author

etherealjoy commented Jun 10, 2018

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"

@etherealjoy
Copy link
Contributor Author

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

@topce
Copy link
Contributor

topce commented Jun 11, 2018

this is broken also in typescript-angular code generator

@wing328
Copy link
Member

wing328 commented Jun 17, 2018

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)

@jmini jmini modified the milestones: 3.0.2, 3.0.3 Jun 18, 2018
@wing328
Copy link
Member

wing328 commented Jun 19, 2018

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

@wing328
Copy link
Member

wing328 commented Jun 20, 2018

Filed #360 to fix it. Please give it a try when you've time.

@etherealjoy
Copy link
Contributor Author

[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<TKey, TValue>' 
requires 2 type arguments		

I merged the changes on my fork but it is not working.

@etherealjoy
Copy link
Contributor Author

Fixed with #360

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants