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

feat(cli): Add inline property to type references from properties in Fern definition with OpenAPI importer #5248

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Swimburger
Copy link
Member

@Swimburger Swimburger commented Nov 21, 2024

Description

In the Fern definition, you can express your desire to inline a type from a property on a type or request:

service:
  endpoints:
    endpointName:
      ...
      request:
        ...
        body:
          ...
          properties:
            bar:
              inline: true
              type: InlineType

types:
  RootType:
    properties:
      bar:
        type: InlineType
        inline: true
  InlineType:
    properties:
      ...

The IR generated from this Fern definition will store the desire to inline a type on the property and on the type declaration. For the type declaration, inline will only be true if all properties reference the type express desire to inline a type.

Changes Made

  • Update Fern definition to allow inline true on properties referencing a type
  • Update OpenAPI parser and OpenAPI IR to pass inline to the generated Fern definition
  • Update Fern to IR generator to pass on inline to property and to type

Testing

  • Unit tests added/updated

Added more test definitions + evaluate existing test definition snapshots.

Copy link

github-actions bot commented Nov 21, 2024


BaseTypeDeclarationSchema:
extends:
inline: optional<boolean>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume this is the only thing that changed? nit: would be nice to remove the formatting changes for this PR

const namedProps = Object.values(types).flatMap((type) => {
if (type.shape.type !== "object") {
return [];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if an inline type is "extended" or if a discriminated union references the inline type as a variant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -283,6 +283,7 @@ types:
type: string
docs: |
A unique name for the property.
inline: optional<boolean>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this property? If a SchemaWithExample contains another SchemaWithExample that is not a reference, you already know the type is inlined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words, in openapi-ir-to-fern when you call buildTypeDeclaration() and then that calls buildTypeReference and that calls buildTypeDeclaration again, you know that the second declaration call is for an inlined type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we just tracked depth of call, then i think we should be able to control inline based on that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants