apple / swift-openapi-generator

Generate Swift client and server code from an OpenAPI document.
https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
Apache License 2.0
1.21k stars 87 forks source link

Expose internal symbols #533

Closed mapedd closed 2 months ago

mapedd commented 2 months ago

Question

I have a SPM target that uses OpenAPI Swift generator to generate client code, it's called APIInteractor I'd like to use this module in my tests, APIIntegrationTests but I can't find a way to use any type that's generated, such as (in my example) Components.Schemas.EventId.

All those types are marked internal as they are code generated using a spm plugin. Is it possible to expose them to test target?

Something like this does not help:

public typealias ProductId = Components.Schemas.ProductId

I'm getting:

Type alias cannot be declared public because its underlying type uses an internal type

Edit: I know this can be done if I invoke the code gen manually , but spm plugins are so awesome :)

mapedd commented 2 months ago

I guess this should do the job:

accessModifier (optional): a string. Customizes the visibility of the API of the generated code.

public: Generated API is accessible from other modules and other packages (if included in a product).

package: Generated API is accessible from other modules within the same package or project.

internal (default): Generated API is accessible from the containing module only.

generator has accessModifier config

mapedd commented 2 months ago

yup, that was it

mapedd commented 2 months ago

example config file for this to work:

generate:
  - types
  - client
accessModifier: public
simonjbeaumont commented 2 months ago

@mapedd just to clear this up for others, IIUC, you could have achieved this with package, instead of public and not risk leaking these types through your public API.

Another option is to use @testable import in your tests.