{
// ...
"definitions": {
"Color": {
"description": "",
"enum": [
0,
1,
2
],
"type": "integer",
"x-enumNames": [
"RED",
"GREEN",
"BLUE"
]
}
}
}
{
"consumes": [
"application/json"
],
"definitions": {
"Bar": {
"additionalProperties": false,
"properties": {
"A": {
"type": "string"
},
"B": {
"format": "int32",
"type": "integer"
},
"Baz": {
"$ref": "#/definitions/Baz"
},
"C": {
"format": "date-time",
"type": "string"
}
},
"required": [
"B",
"C"
],
"type": "object"
},
"Baz": {
"additionalProperties": false,
"properties": {
"Color": {
"$ref": "#/definitions/Color"
},
"D": {
"format": "decimal",
"type": "number"
}
},
"required": [
"D",
"Color"
],
"type": "object"
},
"Color": {
"description": "",
"enum": [
0,
1,
2
],
"type": "integer",
"x-enumNames": [
"RED",
"GREEN",
"BLUE"
]
}
},
"info": {
"title": "",
"version": ""
},
"parameters": {},
"paths": {
"/api/Foo/GetBar": {
"get": {
"operationId": "Foo_GetBar",
"parameters": [
{
"format": "int32",
"in": "query",
"name": "id",
"required": true,
"type": "integer",
"x-nullable": false
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/Bar"
},
"x-nullable": true
}
},
"tags": [
"Foo"
]
}
},
"/api/Foo/GetBarDescriptions": {
"get": {
"operationId": "Foo_GetBarDescriptions",
"parameters": [],
"responses": {
"200": {
"description": "",
"schema": {
"items": {
"type": "string"
},
"type": "array"
},
"x-nullable": true
}
},
"tags": [
"Foo"
]
}
},
"/api/Foo/SetBar": {
"post": {
"operationId": "Foo_SetBar",
"parameters": [
{
"in": "body",
"name": "value",
"required": true,
"schema": {
"$ref": "#/definitions/Bar"
},
"x-nullable": true
}
],
"responses": {
"204": {
"description": ""
}
},
"tags": [
"Foo"
]
}
}
},
"produces": [
"application/json"
],
"responses": {},
"schemes": [],
"securityDefinitions": {},
"swagger": "2.0",
"x-generator": "NSwag v11.14.0.0 (NJsonSchema v9.10.24.0 (Newtonsoft.Json v9.0.0.0))"
}
I found this StackOverflow question which wants to create an interface for
Colorbased on the following JSON input:{ // ... "definitions": { "Color": { "description": "", "enum": [ 0, 1, 2 ], "type": "integer", "x-enumNames": [ "RED", "GREEN", "BLUE" ] } } }The expected result is:
But swaxios 0.1.2 generates:
Complete input file:
{ "consumes": [ "application/json" ], "definitions": { "Bar": { "additionalProperties": false, "properties": { "A": { "type": "string" }, "B": { "format": "int32", "type": "integer" }, "Baz": { "$ref": "#/definitions/Baz" }, "C": { "format": "date-time", "type": "string" } }, "required": [ "B", "C" ], "type": "object" }, "Baz": { "additionalProperties": false, "properties": { "Color": { "$ref": "#/definitions/Color" }, "D": { "format": "decimal", "type": "number" } }, "required": [ "D", "Color" ], "type": "object" }, "Color": { "description": "", "enum": [ 0, 1, 2 ], "type": "integer", "x-enumNames": [ "RED", "GREEN", "BLUE" ] } }, "info": { "title": "", "version": "" }, "parameters": {}, "paths": { "/api/Foo/GetBar": { "get": { "operationId": "Foo_GetBar", "parameters": [ { "format": "int32", "in": "query", "name": "id", "required": true, "type": "integer", "x-nullable": false } ], "responses": { "200": { "description": "", "schema": { "$ref": "#/definitions/Bar" }, "x-nullable": true } }, "tags": [ "Foo" ] } }, "/api/Foo/GetBarDescriptions": { "get": { "operationId": "Foo_GetBarDescriptions", "parameters": [], "responses": { "200": { "description": "", "schema": { "items": { "type": "string" }, "type": "array" }, "x-nullable": true } }, "tags": [ "Foo" ] } }, "/api/Foo/SetBar": { "post": { "operationId": "Foo_SetBar", "parameters": [ { "in": "body", "name": "value", "required": true, "schema": { "$ref": "#/definitions/Bar" }, "x-nullable": true } ], "responses": { "204": { "description": "" } }, "tags": [ "Foo" ] } } }, "produces": [ "application/json" ], "responses": {}, "schemes": [], "securityDefinitions": {}, "swagger": "2.0", "x-generator": "NSwag v11.14.0.0 (NJsonSchema v9.10.24.0 (Newtonsoft.Json v9.0.0.0))" }The
x-enumNamesproperty is a custom property (indicated by the leadingx-) but it seems to be very popular because it has been asked for in many other projects before:Doc on enum flag: