Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IApiContentModel, IApiElementModel and IApiContentResponseModel are missing #37

Open
DmytroKryvoruchenko opened this issue Sep 20, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@DmytroKryvoruchenko
Copy link

Which version of the package are you using?

13.0.0

Which Umbraco version are you using? For example: 12.2.0 - don't just write v12

13.3.2

Bug summary

Missed schemas:
IApiContentModel
IApiElementModel
IApiContentResponseModel

Steps to reproduce

Go to swagger and call GET /umbraco/delivery/api/v2/content/item/{path} with any path.
I see issue, that type is missing:
image

Expected result / actual result

Expected: no missing schemas
Actual: few schemas are missing

@DmytroKryvoruchenko DmytroKryvoruchenko added the bug Something isn't working label Sep 20, 2024
@lauraneto
Copy link
Contributor

Hi @DmytroKryvoruchenko ,

Sorry for the delay!
I've done a new release for v13 (13.1.0), which contains some changes to the way the swagger is generated.
Let me know if updating fixes the issue!

@DmytroKryvoruchenko
Copy link
Author

DmytroKryvoruchenko commented Nov 28, 2024

Hi @lauraneto,

Thanks for new version!

I have checked it but issue is still appearing in 13.1.0.
My setting to enable extension are:

{
  "DeliveryApiExtensions": {
    "Preview": {
      "Enabled": true,
      "Media": {
        "Enabled": true
      },
      "AllowedUserGroupAliases": [],
      "ContentAppWeight": -99
    },
    "TypedSwagger": {
      "Enabled": true,
      "Mode": "Compatibility"
    }
  }
}

Is it correct one?

Also I did workaround for it (just add empty models like this):

// ReSharper disable All
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace [your_namespace];

// Ignore names
public class IApiContentModel {}
public class IApiElementModel {}
public class IApiContentResponseModel {}

public class MissedSchemasDocumentFilter : IDocumentFilter
{
    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {
        var missedTypes = new List<Type>()
        {
            typeof(IApiContentModel),
            typeof(IApiElementModel),
            typeof(IApiContentResponseModel),
        };
        foreach (var missedType in missedTypes)
        {
            var schema = context.SchemaGenerator.GenerateSchema(missedType, context.SchemaRepository);
            // Use the class name as the schema ID
            var schemaId = missedType.Name;
            // Add the schema to the components section with the custom schema ID
            if (!swaggerDoc.Components.Schemas.ContainsKey(schemaId))
            {
                swaggerDoc.Components.Schemas[schemaId] = schema;
            }
        }
    }
} 

and add it:

umbracoBuilder.Services.AddSwaggerGen(options =>
{
  options.DocumentFilter<MissedSchemasDocumentFilter>();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants