swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.09k stars 6.03k forks source link

[csharp] ApiResponseDelete.cs is not being generated but referred to by generated code #5676

Open sbeh opened 7 years ago

sbeh commented 7 years ago
Description

The csharp client is missing one class file (in this case ApiResponseDelete.cs). Other classes use instances of the missing ApiResponseDelete class.

Swagger-codegen version

2.2.2

Swagger declaration file content or url

https://docs.newsletter2go.com/doc/swagger.json

Command line used for generation
> java -jar swagger-codegen-cli-2.2.2.jar -l csharp -i https://docs.newsletter2go.com/doc/swagger.json
Steps to reproduce
> java -jar swagger-codegen-cli-2.2.2.jar -l csharp -i https://docs.newsletter2go.com/doc/swagger.json
> build.bat
 ...
src\IO.Swagger\Api\RecipientApi.cs(1497,62): error CS0246: The type or namespace
        name 'ApiResponseDelete' could not be found (are you missing a using
        directive or an assembly reference?)
 ...
jimschubert commented 7 years ago

This looks to be a problem with swagger-parser. I debugged against the referenced specification and swagger.getDefinitions() doesn't include ApiResponseDelete.

image

I thought it may be a problem with missing type on the schema, but the OpenAPI 2.0 specification and JSON Schema don't appear to require type or 1..n properties in the properties object. The JSON Schema goes as far as to say that an empty schema doesn't even mean there are no properties, only that the properties aren't known. It's not clear if that refers to a schema defined as ApiResponseDelete: { } or ApiResponseDelete: { description:"",properties:{} }. The latter is how the linked schema defines the type.

Somebody may want to verify this behavior to make sure I'm not misspelling a key or something.

You can edit bin/csharp-petstore.sh with the above schema, then setup IntelliJ or whatever IDE to debug on port 5009. I put a breakpoint in DefaultGenerator#processOperation.

export JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,address=5009,suspend=y"
JAVA_OPTS="$JAVA_OPTS -DdebugModels -DdebugOperations -DdebugSwagger" ./bin/csharp-petstore.sh

Start your debugger and you can walk through the generation of the above schema to verify the type is missing from swagger.getDefinitions().

When done debugging, unset or clear JAVA_OPTS:

export JAVA_OPTS=""

I have a feeling this bug will have to get moved to swagger-parser.

wing328 commented 7 years ago

@sbeh Please file the issue with Swagger Parser instead as suggested by Jim.

sbeh commented 7 years ago

@wing328 done

wing328 commented 7 years ago

@sbeh also when I used https://editor2.swagger.io to load the spec (https://docs.newsletter2go.com/doc/swagger.json), I got many errors.