Open crafty615 opened 6 years ago
I'm working with crafty on this and I was able to get the client to generate after some debugging. What I found is that autorest doesn't like how we're generating enums with nswag. I'm not 100% familiar with the swagger spec - is the generated swagger for enums in that spec valid? Should this be a bug report to NSwag instead?
The results of the debugging was that with current master of the modeler project it's blowing up on line 142 of SwaggerModeler.cs:
objectType.BaseModelType = GeneratedTypes[ExtendedTypes[typeName]];
The extended types dict maps the type name from Animal_Diet
to Diet
, however the generated types dict only contains a def for Animal_Diet
. The same happens to the size enum. I did not dig in much further than that.
The swagger looks valid.
we don't support x-enumNames
-- but that shouldn't cause anything to blow up.
You can add x-ms-enum
definitions, (which is required to get generated classes for enums in AutoRest) .. see : http://azure.github.io/autorest/extensions/#x-ms-enum
I'm working with crafty on this and I was able to get the client to generate after some debugging. What I found is that autorest doesn't like how we're generating enums with nswag. I'm not 100% familiar with the swagger spec - is the generated swagger for enums in that spec valid? Should this be a bug report to NSwag instead?
The results of the debugging was that with current master of the modeler project it's blowing up on line 142 of SwaggerModeler.cs:
objectType.BaseModelType = GeneratedTypes[ExtendedTypes[typeName]];
The extended types dict maps the type name from
Animal_Diet
toDiet
, however the generated types dict only contains a def forAnimal_Diet
. The same happens to the size enum. I did not dig in much further than that.
I am running into a similar issue, is there anything that can be done to avoid this? Is this a problem with the swagger definition?
I found the answer to my issue in this thread. Using a config.yaml to change my swagger document's references to the enums in a way that autorest will be happy about.
Not getting any useful information in the stacktrace. Cannot seem to figure out what exactly is causing the key not found exception.
output:
Readme.md:
Swagger Json input:
NSwag Swagger Json
``` { "x-generator": "NSwag v11.16.1.0 (NJsonSchema v9.10.41.0 (Newtonsoft.Json v9.0.0.0))", "swagger": "2.0", "info": { "title": "NSwagProof.WebService", "version": "1.0.0" }, "host": "localhost:8100", "schemes": [ "http" ], "consumes": [ "application/json" ], "produces": [ "application/json" ], "paths": { "/animals": { "get": { "tags": [ "Animal" ], "summary": "Gets all animals", "operationId": "Animal_GetAllAnimals", "responses": { "200": { "x-nullable": true, "description": "List of Animals", "schema": { "type": "array", "items": { "$ref": "#/definitions/Animal" } } } } }, "post": { "tags": [ "Animal" ], "summary": "Adds an Animal", "operationId": "Animal_AddAnimal", "consumes": [ "application/json" ], "parameters": [ { "name": "Animal", "in": "body", "required": true, "schema": { "$ref": "#/definitions/Animal" } } ], "responses": { "200": { "x-nullable": true, "description": "Animal", "schema": { "$ref": "#/definitions/Animal" } } } } }, "/animals/{id}": { "get": { "tags": [ "Animal" ], "summary": "Gets a specific animal", "operationId": "Animal_GetAnimal", "parameters": [ { "type": "integer", "name": "id", "in": "path", "required": true, "description": "Animal's ID", "format": "int32", "x-nullable": false } ], "responses": { "200": { "x-nullable": true, "description": "Animal", "schema": { "$ref": "#/definitions/Animal" } } } }, "put": { "tags": [ "Animal" ], "summary": "Updates an Animal", "operationId": "Animal_UpdateAnimal", "consumes": [ "application/json" ], "parameters": [ { "type": "integer", "name": "id", "in": "path", "required": true, "description": "Animal's ID", "format": "int32", "x-nullable": false }, { "name": "Animal", "in": "body", "required": true, "schema": { "$ref": "#/definitions/Animal" } } ], "responses": { "200": { "x-nullable": true, "description": "Animal", "schema": { "$ref": "#/definitions/Animal" } } } } }, "/test/ping": { "get": { "tags": [ "Test" ], "summary": "Pings server side and returns a 200", "operationId": "Test_Ping", "responses": { "200": { "x-nullable": true, "description": "200 OK", "schema": { "type": "file" } } } } }, "/test/post": { "post": { "tags": [ "Test" ], "summary": "Tests the Swagger body param attribute with a type not initially registered", "operationId": "Test_PostBodyTest", "consumes": [ "application/json" ], "parameters": [ { "name": "RandomTestContainer", "in": "body", "required": true, "schema": { "title": "RandomTestContainer", "type": "object", "description": "Random container object for a test", "required": [ "Thing" ], "properties": { "Thing": { "type": "integer", "description": "Thing that does things", "format": "int32" } } } } ], "responses": { "200": { "x-nullable": true, "description": "", "schema": { "type": "string" } } } } } }, "definitions": { "Animal": { "type": "object", "discriminator": "AnimalType", "description": "Animal Base Class", "required": [ "NumberOfLegs", "IsDomesticated", "Diet", "IsExtinct", "AnimalType" ], "properties": { "Id": { "type": "integer", "description": "Identifier", "format": "int32" }, "Species": { "type": "string", "description": "Animals species scientific name" }, "NumberOfLegs": { "type": "integer", "description": "Amount of legs the animal has", "format": "int32" }, "IsDomesticated": { "type": "boolean", "description": "States whether the animal has been domesticated as a pet" }, "Diet": { "description": "What type of food the animal eats", "allOf": [ { "$ref": "#/definitions/Diet" } ] }, "IsExtinct": { "type": "boolean", "description": "Whether there are any of the same animal still alive" }, "AnimalType": { "type": "string" } } }, "Diet": { "type": "string", "description": "What the animal eats", "x-enumNames": [ "Omnivorous", "Carnivorous", "Herbivorous" ], "enum": [ "Omnivorous", "Carnivorous", "Herbivorous" ] }, "Cat": { "type": "object", "description": "Cat Class", "required": [ "IsHairless" ], "properties": { "Breed": { "type": "string", "description": "What type of cat" }, "IsHairless": { "type": "boolean", "description": "Whether the cat has hair or not" } }, "allOf": [ { "$ref": "#/definitions/DomesticatedAnimal" } ] }, "DomesticatedAnimal": { "type": "object", "discriminator": "AnimalType", "description": "Domesticated Animal Base Class", "required": [ "Size", "AnimalType" ], "properties": { "Name": { "type": "string", "description": "Name of the Animal" }, "Size": { "description": "Size of the animal", "allOf": [ { "$ref": "#/definitions/Size" } ] }, "Allergies": { "type": "array", "description": "Allergies the animal may have", "items": { "$ref": "#/definitions/Allergy" } }, "AnimalType": { "type": "string" } }, "allOf": [ { "$ref": "#/definitions/Animal" } ] }, "Size": { "type": "string", "description": "Size of the Animal", "x-enumNames": [ "Tiny", "Small", "Medium", "Large", "Huge" ], "enum": [ "Tiny", "Small", "Medium", "Large", "Huge" ] }, "Allergy": { "type": "object", "description": "Allergy Class", "properties": { "Name": { "type": "string", "description": "Name of the Allergy" }, "DictionaryThing": { "type": "object", "description": "Dictionary to tests swagger stuff", "additionalProperties": { "type": "integer", "format": "int32" } } } }, "Dog": { "type": "object", "description": "Dog Class", "required": [ "IsAGoodBoy" ], "properties": { "Breed": { "type": "string", "description": "The type of dog" }, "IsAGoodBoy": { "type": "boolean", "description": "Whether the dog is a good boy or not. (He is)" } }, "allOf": [ { "$ref": "#/definitions/DomesticatedAnimal" } ] }, "Chupacabra": { "type": "object", "description": "Chupacabra Class", "required": [ "NumberOfGoatsSlaughtered" ], "properties": { "NumberOfGoatsSlaughtered": { "type": "integer", "description": "Number of goats the Chupacabra has slaughtered", "format": "int32" } }, "allOf": [ { "$ref": "#/definitions/Animal" } ] } } } ```