question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using SwaggerToCSharpWebApiControllerGenerator with $ref pointing to external files

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:25 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
RicoSutercommented, Oct 18, 2017

v11.10

1reaction
InstanceOfAnObjectcommented, Oct 17, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found