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

[BUG] OpenAPI type names of types in unknown context #6

Open
Supereg opened this issue Aug 30, 2021 · 3 comments
Open

[BUG] OpenAPI type names of types in unknown context #6

Supereg opened this issue Aug 30, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@Supereg
Copy link
Member

Supereg commented Aug 30, 2021

Describe the bug
When retrieving the type name via the ApodiniTypeInformation framework of a type which is e.g. declared in a function, the OpenAPI doesn't support those as the type name includes characters which are disallowed in OpenAPI schema references.

To Reproduce
Given the example of (assuming this lies in a target name ExampleTarget):

struct OuterTest {
    static func test() {
        struct Test {}

        print(String(reflecting: Test.self))
    }
}

OuterTest.test()

it will print the string ExampleTarget.OuterTest.(unknown context at $109f9c144).(unknown context at $109f9c14c).Test.

ApodiniTypeInformation will create a TypeName which the type Test, target name ExampleTarget and the nested type (unknowncontextat$109f9c144) and (unknowncontextat$109f9c14c).

OpenAPI will just use the concatenation of those when creating a schema entry. This is problematic when trying to reference it, as the type name contains the illegal character (, ) and $.

Expected behavior

It is not entirely clear what the best solution is. One might simple replace those illegal characters, but then we still have an unstable type name (the hex digits change for every compilation step). If we just remove those unknown context entries, it might result in a name collision with a type with the same name defined on the level without those "context" levels or with a type name placed in another function.

@eldcn
Copy link
Collaborator

eldcn commented Sep 19, 2021

This is not an issue at all for OpenAPI schemas. A type defined inside of a function, is accessible only inside the scope of that function, hence there is no way to use Test as a return type of a Handler, or as a property of a Content type

@Supereg
Copy link
Member Author

Supereg commented Sep 19, 2021

Ah yes, you are right. Maybe it would make sense to move this issue to the TypeInformation framework so those „unknown context“ cases are represented properly in the TypeName structure?

@PSchmiedmayer
Copy link
Contributor

@Supereg @eldcn Yes, it would be great to move that issue to the TypeInformation framework 👍

@Supereg Supereg transferred this issue from Apodini/Apodini Oct 25, 2021
@Supereg Supereg added the bug Something isn't working label Jan 31, 2022
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

3 participants