delphimvcframework icon indicating copy to clipboard operation
delphimvcframework copied to clipboard

MVCSwagParam ptArray Bug

Open st1gok opened this issue 5 years ago • 17 comments

Hi! I use RC6 and applied changes from fix https://github.com/danieleteti/delphimvcframework/issues/376

When you use MVCSwagParam(plQuery, 'types', 'types', ptArray, false,'','money,loading,unloading')

result in json: { "in": "query", "name": "types", "description": "types", "type": "array", "enum": [ "money", "loading", "unloading" ] }

but it should be: { "name": "types", "in": "query", "description": "types", "type": "array", "items": { "type": "string", "enum": [ "money", "loading", "unloading" ] } }

st1gok avatar May 03 '20 10:05 st1gok

I will check this behavior

joaoduarte19 avatar May 03 '20 10:05 joaoduarte19

Also I have problem with [MVCSwagResponses(200, 'ok', INDEX_JSON_SCHEMA)] where INDEX_JSON_SCHEMA = '{' + sLineBreak + ' "type": "array",' + sLineBreak + ' "items": {' + sLineBreak + ' "type": "object",' + sLineBreak + ' "properties": {' + sLineBreak + ' "application": {' + sLineBreak + ' "type": "string",' + sLineBreak + ' "description": "Application Name"' + sLineBreak + ' },' + sLineBreak + ' "online": {' + sLineBreak + ' "type": "boolean",' + sLineBreak + ' "description": "Defines if the server is online"' + sLineBreak + ' },' + sLineBreak + ' "serverdatetime": {' + sLineBreak + ' "type": "string",' + sLineBreak + ' "description": "Current server time"' + sLineBreak + ' }' + sLineBreak + ' }' + sLineBreak + ' },' + sLineBreak + '}';

maybe these errors are related

st1gok avatar May 03 '20 11:05 st1gok

Hi! I use RC6 and applied changes from fix #376

When you use MVCSwagParam(plQuery, 'types', 'types', ptArray, false,'','money,loading,unloading')

result in json: { "in": "query", "name": "types", "description": "types", "type": "array", "enum": [ "money", "loading", "unloading" ] }

but it should be: { "name": "types", "in": "query", "description": "types", "type": "array", "items": { "type": "string", "enum": [ "money", "loading", "unloading" ] } }

Using the last commit from dmvc I did these tests and when I define the parameter type as an array, the generated JsonSchema shows it as an array. However when you use enumerators the value of an enumerator cannot be an array. See https://swagger.io/docs/specification/2-0/enums/

joaoduarte19 avatar May 03 '20 22:05 joaoduarte19

Also I have problem with [MVCSwagResponses(200, 'ok', INDEX_JSON_SCHEMA)] where INDEX_JSON_SCHEMA = '{' + sLineBreak + ' "type": "array",' + sLineBreak + ' "items": {' + sLineBreak + ' "type": "object",' + sLineBreak + ' "properties": {' + sLineBreak + ' "application": {' + sLineBreak + ' "type": "string",' + sLineBreak + ' "description": "Application Name"' + sLineBreak + ' },' + sLineBreak + ' "online": {' + sLineBreak + ' "type": "boolean",' + sLineBreak + ' "description": "Defines if the server is online"' + sLineBreak + ' },' + sLineBreak + ' "serverdatetime": {' + sLineBreak + ' "type": "string",' + sLineBreak + ' "description": "Current server time"' + sLineBreak + ' }' + sLineBreak + ' }' + sLineBreak + ' },' + sLineBreak + '}';

maybe these errors are related

Would that be the JsonSchema of the SwaggerDoc example? image

Is working as expected

joaoduarte19 avatar May 03 '20 22:05 joaoduarte19

Would that be the JsonSchema of the SwaggerDoc example?

yes, if this object then working, but me need array objects

st1gok avatar May 03 '20 22:05 st1gok

Hi! I use RC6 and applied changes from fix #376 When you use MVCSwagParam(plQuery, 'types', 'types', ptArray, false,'','money,loading,unloading') result in json: { "in": "query", "name": "types", "description": "types", "type": "array", "enum": [ "money", "loading", "unloading" ] } but it should be: { "name": "types", "in": "query", "description": "types", "type": "array", "items": { "type": "string", "enum": [ "money", "loading", "unloading" ] } }

Using the last commit from dmvc I did these tests and when I define the parameter type as an array, the generated JsonSchema shows it as an array. However when you use enumerators the value of an enumerator cannot be an array. See https://swagger.io/docs/specification/2-0/enums/

I tested this in editor.swagger.io

array may contain enum https://swagger.io/docs/specification/2-0/describing-parameters/ image

st1gok avatar May 03 '20 22:05 st1gok

yes, if this object then working, but me need array objects

This object represented as an array should look like this:

{
	"type": "array",
	"items": {
		"type": "object",
		"properties": {
			"application": {
				"type": "string",
				"description": "Application Name"
			},
			"online": {
				"type": "boolean",
				"description": "Defines if the server is online"
			},
			"serverdatetime": {
				"type": "string",
				"description": "Current server time"
			}
		}
	}
}

joaoduarte19 avatar May 03 '20 22:05 joaoduarte19

yes, if this object then working, but me need array objects

This object represented as an array should look like this:

{
	"type": "array",
	"items": {
		"type": "object",
		"properties": {
			"application": {
				"type": "string",
				"description": "Application Name"
			},
			"online": {
				"type": "boolean",
				"description": "Defines if the server is online"
			},
			"serverdatetime": {
				"type": "string",
				"description": "Current server time"
			}
		}
	}
}

I agree see my post https://github.com/danieleteti/delphimvcframework/issues/377#issuecomment-623094609 but this not worked

st1gok avatar May 03 '20 22:05 st1gok

I think you're missing something. In my tests it is working correctly; Untitled-1

See this attached sample. Enumerators and array of objects work correctly: swaggerdoc.zip

joaoduarte19 avatar May 03 '20 23:05 joaoduarte19

Ok, I test tomorrow and answer

st1gok avatar May 03 '20 23:05 st1gok

I think you're missing something. In my tests it is working correctly; Untitled-1

See this attached sample. Enumerators and array of objects work correctly: swaggerdoc.zip

Yes, array of objects work correctly, I have extra comma in my example. Enums work is single, but not array of enum. Need next result :

{
            "name": "types",
            "in": "query",
            "description": "types",
            "required": false,
            "type": "array",
            "items": {
                "type": "string",
                "enum": [
                    "money",
                    "loading",
                    "unloading"
                ]
            }
   }

st1gok avatar May 04 '20 08:05 st1gok

Enums work is single, but not array of enum.

Indeed, swagger middleware does not support enumerators as an array. We will implement this functionality soon.

joaoduarte19 avatar May 04 '20 10:05 joaoduarte19

Is it possible for now to implement this parameter through AJsonSchema?

st1gok avatar May 04 '20 11:05 st1gok

I believe it is possible. However it is necessary to test to be sure of this.

joaoduarte19 avatar May 04 '20 11:05 joaoduarte19

I couldn’t do it (

st1gok avatar May 04 '20 12:05 st1gok

What is the status of this problem ? We are facing similair problem now.

blitt001 avatar Jan 04 '21 14:01 blitt001

What is the status of this problem ? We are facing similair problem now.

When we add support for OpenAPI 3.0 we intend to correct this problem. What problem are you having? You can describe it, so we can try to solve it.

joaoduarte19 avatar Jan 04 '21 19:01 joaoduarte19