autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Autorest V3 csharp petstore example failing on 'source' parameter when include requestBody

Open OzBob opened this issue 6 years ago • 7 comments

After converting https://petstore.swagger.io/v2/swagger.json to OpenAPI 3.0.1

by loading it into https://editor.swagger.io/ then Edit | Convert to Open API 3 - > sending it to https://converter.swagger.io/api/convert

downloading the resultant json and using

Autorest --v3 --input-file=petstore3.json --csharp --output-folder=petstore --namespace=petstore

results in:

   Loading AutoRest extension '@microsoft.azure/autorest.csharp' (~2.3.79->2.3.84)
   Loading AutoRest extension '@microsoft.azure/autorest.modeler' (2.3.55->2.3.55)
FATAL: System.ArgumentNullException: Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable1 source, Func2 selector)
   at AutoRest.Modeler.Model.RequestBody.AsParameters() in /opt/vsts/work/1/s/src/Model/RequestBody.cs:line 38

Note: When running the https://github.com/Azure/autorest.modeler/pull/59 test project there are no errors.

Is autorest.modeler 2.3.55 uptodate?

Feature Request : add a --debug flag to have progress 'info' e.g. 'paths' / node name info etc. output to console during run of extensions.

Is there developer guidance as to how to import a custom build of an extension into the autorest installed locally?

OzBob avatar Mar 27 '20 11:03 OzBob

if remove this section of the petstore.json, no more errors:

,
"requestBody": {
	"content": {
		"application/x-www-form-urlencoded": {
			"schema": {
				"properties": {
					"name": {
						"type": "string",
						"description": "Updated name of the pet"
					},
					"status": {
						"type": "string",
						"description": "Updated status of the pet"
					}
				}
			}
		}
	}
},

OzBob avatar Mar 27 '20 12:03 OzBob

Please ignore

Incorrectly parsed old schema in.

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md : "The request body applicable for this operation. The requestBody is only supported in HTTP methods where the HTTP 1.1 specification RFC7231 has explicitly defined semantics for request bodies. In other cases where the HTTP spec is vague, requestBody SHALL be ignored by consumers."

OzBob avatar Mar 29 '20 12:03 OzBob

but .... according to Swagger.io converter issue the "Paramters/in:body" should be and now is converted to requestBody??

OzBob avatar Mar 29 '20 12:03 OzBob

Hello, i'm facing the same issue, with my openapi 3 json documentation.

Here is the autorest command line : autorest --input-file=swagger.json --csharp --v3 --add-credentials --output-folder=RestClient --namespace=MyNamespace --debug The exception is thrown in the modeler pipeline. I cloned the modeler project running unit test with the same json file the test passes. Is there a way to load a custom build of the modeler ?

autorest : FATAL: System.ArgumentNullException: Value cannot be null.
+ autorest  --input-file=swagger.json --csharp --v3 --add-credentials - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (FATAL: System.A...cannot be null.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Parameter name: source
   at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable1 source, Func2 selector)
   at AutoRest.Modeler.Model.RequestBody.AsParameters()
   at AutoRest.Modeler.SwaggerModeler.Unwrap(SwaggerParameter swaggerParameter)
   at AutoRest.Modeler.OperationBuilder.BuildMethodParameters(Method method)
   at AutoRest.Modeler.OperationBuilder.BuildMethod(HttpMethod httpMethod, String url, String methodName, String methodGroup)
   at AutoRest.Modeler.SwaggerModeler.BuildMethod(HttpMethod httpMethod, String url, String name, Operation operation)
   at AutoRest.Modeler.SwaggerModeler.Build(ServiceDefinition serviceDefinition)
   at AutoRest.Modeler.Program.<ProcessInternal>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NewPlugin.<Process>d__15.MoveNext()
C:\Users\HossamLaanait\.autorest\@[email protected]\node_modules\@autorest\core\dist\lib\pipeline\pipeline.js - FAILURE {}

laanaithossam avatar Apr 02 '20 21:04 laanaithossam

@laanaithossam add a 'thumbsup' to the first post in this issue and it might get more attention.

OzBob avatar Apr 29 '20 03:04 OzBob

Looks like the same issue as #3441?

kevinoid avatar May 11 '20 17:05 kevinoid

Closing as duplicate of #3441.

daviwil avatar Oct 08 '20 23:10 daviwil