Open Closed

Swagger, OpenAPI and importing definition into Azure API Gateway #5365


User avatar
0
hothsv created
  • ABP Framework version: v7.2.3
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:

Create a new application using suite, microservice template and add CMS administration I have configured the swagger tool as below however Azure API Gateway will not allow importing as the definition contains invalid output.

How do I get every type to be resolved

            options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion });
            options.DocInclusionPredicate((docName, description) => true);
            //options.CustomSchemaIds(type => type.FullName);
            options.UseInlineDefinitionsForEnums();
            options.UseAllOfToExtendReferenceSchemas();
            options.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
            options.IgnoreObsoleteActions();
            options.IgnoreObsoleteProperties();
            options.CustomSchemaIds(type => type.FullName);

One or more fields contain incorrect values: Parsing error(s): The key 'Volo.Abp.Application.Dtos.ListResultDto1[[Volo.Abp.LanguageManagement.Dto.LanguageDto, Volo.Abp.LanguageManagement.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.ListResultDto1[[Volo.CmsKit.Admin.Polls.PollWidgetDto, Volo.CmsKit.Pro.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.ListResultDto1[[Volo.CmsKit.Menus.MenuItemDto, Volo.CmsKit.Common.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.ListResultDto1[[Volo.CmsKit.Public.Comments.CommentWithDetailsDto, Volo.CmsKit.Public.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.ListResultDto1[[Volo.CmsKit.Public.Reactions.ReactionWithSelectionDto, Volo.CmsKit.Public.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.Abp.AuditLogging.AuditLogDto, Volo.Abp.AuditLogging.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.Abp.AuditLogging.EntityChangeDto, Volo.Abp.AuditLogging.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.Abp.LanguageManagement.Dto.LanguageDto, Volo.Abp.LanguageManagement.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.Abp.LanguageManagement.Dto.LanguageTextDto, Volo.Abp.LanguageManagement.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.Abp.TextTemplateManagement.TextTemplates.TemplateDefinitionDto, Volo.Abp.TextTemplateManagement.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Admin.Blogs.BlogDto, Volo.CmsKit.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Admin.Blogs.BlogPostListDto, Volo.CmsKit.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Admin.Comments.CommentWithAuthorDto, Volo.CmsKit.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Admin.Menus.PageLookupDto, Volo.CmsKit.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Admin.Newsletters.NewsletterRecordDto, Volo.CmsKit.Pro.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Admin.Pages.PageDto, Volo.CmsKit.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Admin.Polls.PollDto, Volo.CmsKit.Pro.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Admin.UrlShorting.ShortenedUrlDto, Volo.CmsKit.Pro.Admin.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Contents.BlogPostCommonDto, Volo.CmsKit.Common.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto1[[Volo.CmsKit.Tags.TagDto, Volo.CmsKit.Common.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-]+$'. [#/components] The key 'Volo.Abp.Application.Dtos.PagedResultDto`1[[Volo.CmsKit.Users.CmsUserDto, Volo.CmsKit.Common.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9.-_]+$'. [#/components] Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specification https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.yaml).


11 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://support.abp.io/QA/Questions/2770/Parsing-errors-The-input-OpenAPI-file-is-not-valid-for-the-OpenAPI-specification

  • User Avatar
    0
    hothsv created

    Hi

    If you have a look at my snippet that configuration has already been applied and the issue is still occuring.

    This is important as in the cloud we use API gateway instead of ocelot for on-premise so the swagger definitions need to be confirming to the openapi spec.

    Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can I reproduce this in app-pro template project?

    abp new BookStore -t app-pro

    Can you share some code and steps? Thanks

  • User Avatar
    0
    hothsv created

    Hi

    If you create a fresh application using suite, abp new BookStore -t app-pro, then add the CMS suite and start the application up.

    Update the .Web as below which should fix the issue.

    private void ConfigureSwaggerServices(IServiceCollection services) { services.AddAbpSwaggerGen( options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "BookStore API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); options.UseInlineDefinitionsForEnums(); options.UseAllOfToExtendReferenceSchemas(); options.CustomSchemaIds(type => type.FullName); } ); }

    If you then open the swagger definition https://localhost:44351/swagger/v1/swagger.json and look at line 7026 and many others you will see that they violate the open api specification.

    "$ref": "#/components/schemas/Volo.Abp.Application.Dtos.PagedResultDto`1[[Volo.Abp.AuditLogging.EntityChangeDto, Volo.Abp.AuditLogging.Application.Contracts, Version=7.2.3.0, Culture=neutral, PublicKeyToken=null]]"

    I would be happy to send you a runnable application if you drop me you email?

    THanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    liming.ma@volosoft.com

    Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I downloaded your project. How can I get Parsing error(s)?

  • User Avatar
    0
    hothsv created

    hi

    I downloaded your project. How can I get Parsing error(s)?

    If you use https://editor.swagger.io/ to validate it you will see the parsing issue

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Im not a swagger expert but you can try that:

    options.SwaggerDoc("v1", new OpenApiInfo { Title = "BookStore API", Version = "v1" });
    options.DocInclusionPredicate((docName, description) => true);
    options.UseInlineDefinitionsForEnums();
    options.UseAllOfToExtendReferenceSchemas();
    options.CustomSchemaIds(type => Regex.Replace(type.FullName, "`|=|\\[|\\]|\\s|,", ""));
    
  • User Avatar
    0
    hothsv created

    Hi

    No you cannot do that as it need to resolve to a type within the swagger definition. This will cause the schema to be invalid

    "text/json": { "schema": { "$ref": "#/components/schemas/Volo.Abp.Application.Dtos.ListResultDto1Volo.Abp.Identity.OrganizationUnitWithDetailsDtoVolo.Abp.Identity.Pro.Application.ContractsVersion7.2.3.0CultureneutralPublicKeyTokennull" } }

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I don't think this is an abp problem because we just using some class as output.

    I think using these classes in a plain asp net core will cause the same problem.

  • User Avatar
    0
    hothsv created

    Ok. Will raise with ASP.NET Core team.

    Thx

Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07