Using SwaggerToCSharpWebApiControllerGenerator with $ref pointing to external files
See original GitHub issueI’ve been battling with this for a while but I can’t make it work. I have the following definitions in my JsonSchema:
...
"definitions": {
"cat": {
"type": "object",
"properties": { "name": { "type": "string" } }
},
"animals": {
"$ref": "./animals.json"
}
}
animals.json looks like this:
{
"dog": {
"type": "object",
"properties": { "name": { "type": "string" } }
}
}
Referencing “cat” works perfectly with: “$ref”: “#/definitions/cat” But if I want to have an external file, in the same folder, with all animals definitions, the file reference doesn’t work.
Searching around I found a lot of URL supported features but nothing related to relative paths on disk.
The C# code is the following:
var doc = SwaggerDocument.FromFileAsync(@"Contracts\pet-service.json").Result;
var settings = new SwaggerToCSharpWebApiControllerGeneratorSettings();
settings.CSharpGeneratorSettings.Namespace = "MyPetsApplication";
var generator = new SwaggerToCSharpWebApiControllerGenerator(doc, settings);
var code = generator.GenerateFile();
Is this really not supported or am I missing something?
Thanks
Issue Analytics
- State:
- Created 6 years ago
- Comments:25 (16 by maintainers)
Top Results From Across the Web
Using SwaggerToCSharpWebApiControllerGenerator with ...
The main problem here is that external $refs are assumed to reference other JSON Schema documents, but your animals.json file does not contain...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
v11.10
Awesome! I’ve updated NSwagStudio from the link you provided, Works! I’ve updated my project NSwag & NJsonSchema dependencies and now everything woks perfectly.
Thanks a lot mate. I’ll be using this for a while now so probably I’ll bother you again 😃
Let me know if I can help you in any way.