christianhelle / refitter

A tool for generating Refit interfaces and contracts from OpenAPI specifications
https://refitter.github.io
MIT License
189 stars 41 forks source link

"While scanning a multi-line double-quoted scalar, found wrong indentation." on valid yaml file #486

Closed eriksteinebach closed 3 weeks ago

eriksteinebach commented 3 weeks ago

Describe the bug I am trying to generate a client with the following command: refitter "https://docs.contentcontroller.com/automation-api/v1/cc-public-api.yml" --skip-validation --namepsace "Rustici.GeneratedCode"

When I use the following tool: https://onlineyamltools.com/validate-yaml to validate the yaml, everything seems valid.

But when I run the command I get the following error:

Error: While scanning a multi-line double-quoted scalar, found wrong indentation. Exception: YamlDotNet.Core.SyntaxErrorException Stack Trace: at YamlDotNet.Core.Scanner.ScanFlowScalar(Boolean isSingleQuoted) at YamlDotNet.Core.Scanner.FetchQuotedScalar(Boolean isSingleQuoted) at YamlDotNet.Core.Scanner.FetchNextToken() at YamlDotNet.Core.Scanner.FetchMoreTokens() at YamlDotNet.Core.Scanner.MoveNextWithoutConsuming() at YamlDotNet.Core.Parser.GetCurrentToken() at YamlDotNet.Core.Parser.ParseBlockMappingValue() at YamlDotNet.Core.Parser.MoveNext() .... at YamlDotNet.Serialization.Deserializer.Deserialize(IParser parser, Type type) at NSwag.OpenApiYamlDocument.FromYamlAsync(String data, String documentPath, SchemaType expectedSchemaType, Func_2 referenceResolverFactory, CancellationToken cancellationToken) at Refitter.Core.OpenApiDocumentFactory.CreateUsingNSwagAsync(String openApiPath) in /_/src/Refitter.Core/OpenApiDocumentFactory.cs:line 50 at Refitter.Core.OpenApiDocumentFactory.CreateAsync(String openApiPath) in /_/src/Refitter.Core/OpenApiDocumentFactory.cs:line 41 at Refitter.Core.RefitGenerator.GetOpenApiDocument(RefitGeneratorSettings settings) in /_/src/Refitter.Core/RefitGenerator.cs:line 35 at Refitter.Core.RefitGenerator.CreateAsync(RefitGeneratorSettings settings) in /_/src/Refitter.Core/RefitGenerator.cs:line 19 at Refitter.GenerateCommand.ExecuteAsync(CommandContext context, Settings settings) in /_/src/Refitter/GenerateCommand.cs:line 45

Support Key: tb7axxy

OpenAPI Specifications https://docs.contentcontroller.com/automation-api/v1/cc-public-api.yml

Additional context I am new to all of this, so it is very possible I just did something stupid myself. And the OpenApi document was not generated by myself, but by another company, so maybe there is something wrong there. I am just not able to figure out what this issue is and would appreciate the help.

christianhelle commented 3 weeks ago

@eriksteinebach Thanks for taking the time to report this. I'll see what I can do

christianhelle commented 3 weeks ago

@eriksteinebach I couldn't get the linked OpenAPI specifications to work as is, but when I re-format it to use single quotes with https://jsonformatter.org/yaml-validator then Refitter stopped complaining and was able to generate code

Here a zip file containing both the re-formatted YAML file and the Refitter output file Archive.zip

christianhelle commented 3 weeks ago

I use NSwag for parsing the OpenAPI specifications document, and it seems that the library doesn't like the OpenAPI specifications that you shared

There is not much I can do about that, and since there's an easy workaround I don't think I'll spend time investigating how the problem in the NSwag code base either

eriksteinebach commented 3 weeks ago

@christianhelle thank you for looking into this. With a couple of other small tweaks I was able to generate the interface, so I think it works. Yes, it looks like more a problem in NSwag. But I can continue for now, so I will leave this be as well.

Thanks for your help!