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.

AutoRest gives bad error message when Swagger spec has broken link

See original GitHub issue

When a Swagger spec has a broken $ref link (i.e. there is “$ref”: “#/definitions/Potato” but no “Potato” in the document’s definitions), AutoRest gives a very unhelpful error message.

FATAL: Error generating client model: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at AutoRest.Swagger.Model.Utilities.ValidationUtilities.IsArrayTypeResponseOperation(Operation op, ServiceDefinition entity)
   at AutoRest.Swagger.Validation.ListOperationNamingWarning.<GetValidationMessages>d__7.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__159`2.MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__159`2.MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at AutoRest.Swagger.SwaggerModeler.Build(ServiceDefinition serviceDefinition)
   at AutoRest.Core.AutoRestController.Generate()
ERROR: Error generating client model: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at AutoRest.Swagger.Model.Utilities.ValidationUtilities.IsArrayTypeResponseOperation(Operation op, ServiceDefinition entity)
   at AutoRest.Swagger.Validation.ListOperationNamingWarning.<GetValidationMessages>d__7.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__159`2.MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__159`2.MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at AutoRest.Swagger.SwaggerModeler.Build(ServiceDefinition serviceDefinition)
   at AutoRest.Core.AutoRestController.Generate()

AutoRest version:

AutoRest Code Generator
(c) 2017 Microsoft Corporation. https://aka.ms/autorest
  Build Information
  Autorest Bootstrapper :  0.9.21
  NetCore framework :      1.0.3
  Latest Core Installed :  1.0.1-20170327-2300-nightly
  Requested Core Version : <none>

Command line: E:\dsmain2\Sql\xdb\manifest\svc\mgmt\WebApiHosting\ARM\Tools>autorest -Input swagger.json -CodeGenerator None

Source file:

{
  "swagger": "2.0",
  "info": {
    "version": "2015-05-01-preview",
    "title": "SqlManagementClient",
    "description": "The Azure SQL Database management API provides a RESTful set of web APIs that interact with Azure SQL Database services to manage your databases. The API enables users to create, retrieve, update, and delete databases, servers, and other entities."
  },
  "host": "management.azure.com",
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/providers/Microsoft.Sql/operations": {
      "get": {
        "tags": [
          "Operations"
        ],
        "operationId": "Operations_GetOperations",
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/Potato"
            }
          }
        },
        "deprecated": false
      }
    }
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
olydiscommented, Apr 20, 2017

It would indeed, but as always, getting as many squigglies as possible as early as possible is highly desirable! Be aware that a single semantic error would then also cause the ScottGu report to say “1 issue”, i.e. fixing issues can increase the number of issues. Wat. We should also not force a run of the semantic validator (that’s configurable and should also be parallelizable, so we don’t wanna introduce a dependency here), so really: The linter should just be robust.

0reactions
olydiscommented, Apr 20, 2017

The PR is open (https://github.com/Azure/autorest/pull/2156), just awaiting approval 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best Practices in API Design - Swagger
Provide enough information in the error codes for an end user to start work on fixing the cause, and, if you feel there's...
Read more >
How to use AutoRest with RDP - Refinitiv Developer Community
AutoRest is an OpenAPI (Swagger) specification code generator. ... This causes a bad request with the following error returned to the application.
Read more >
AutoRest Extensions for OpenAPI 2.0 - Azure documentation
This extension can only be applied on global parameters. If this is applied on any parameter in an operation then it will be...
Read more >
Swashbuckle.AspNetCore - Discover .NET
Swagger tooling for APIs built with ASP.NET Core. Generate beautiful API documentation, including a UI to explore and test operations, directly from your ......
Read more >
WebApi Core / Swagger: "failed to load API definition" error
I eventually started to figure out what was going wrong when I opened that call to swagger.json in its own tab. The error...
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