Skip to content

[generator] fix import references #2081

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

Merged
merged 2 commits into from
Mar 5, 2025
Merged

Conversation

nizox
Copy link
Contributor

@nizox nizox commented Mar 5, 2025

What does this PR do?

This PR fixes an inconsistency in the generator for reference imports. It aligns both get_references_for_model and type_to_typescript handling of objects with additionalProperties and properties fields.

The bug was discovered with this PR.

For the given specification:

components:
  schemas:
    ApplicationSecurityWafCustomRuleCreateAttributes:
      type: object
      description: "Create a new WAF custom rule."
      properties:
        ...
        tags:
          $ref: "#/components/schemas/ApplicationSecurityWafCustomRuleTags"

    ApplicationSecurityWafCustomRuleTags:
      type: object
      description: |-
        Tags associated with the WAF Custom Rule. The concatenation of category and type will form the security
        activity field associated with the traces.
      properties:
        category:
          $ref: "#/components/schemas/ApplicationSecurityWafCustomRuleTagsCategory"
        type:
          type: string
          description: The type of the WAF rule, associated with the category will form the security activity.
          example: "users.login.success"
      additionalProperties:
        type: string

Without the fix the following code was generated:

import { ApplicationSecurityWafCustomRuleCreateAttributesTags } from "./ApplicationSecurityWafCustomRuleCreateAttributesTags";

/**
 * Create a WAF custom rule.
*/
export class ApplicationSecurityWafCustomRuleCreateAttributes {
  ...
  /**
   * Tags associated with the WAF Custom Rule. The concatenation of category and type will form the security
   * activity field associated with the traces.
  */
  "tags": ApplicationSecurityWafCustomRuleTags;

After the fix, the generated and correct code:

import { ApplicationSecurityWafCustomRuleTags } from "./ApplicationSecurityWafCustomRuleTags";

/**
 * Create a WAF custom rule.
*/
export class ApplicationSecurityWafCustomRuleCreateAttributes {
  ...
  /**
   * Tags associated with the WAF Custom Rule. The concatenation of category and type will form the security
   * activity field associated with the traces.
  */
  "tags": ApplicationSecurityWafCustomRuleTags;

Additional Notes

Review checklist

Please check relevant items below:

  • This PR includes all newly recorded cassettes for any modified tests.

  • This PR does not rely on API client schema changes.

    • The CI should be fully passing.
  • Or, this PR relies on API schema changes and this is a Draft PR to include tests for that new functionality.

    • Note: CI shouldn't be run on this Draft PR, as its expected to fail without the corresponding schema changes.

@nizox nizox requested review from a team as code owners March 5, 2025 12:23
@nizox nizox merged commit c2674b5 into master Mar 5, 2025
11 checks passed
@nizox nizox deleted the nicolas.vivet/fix-generator-imports branch March 5, 2025 15:43
github-actions bot pushed a commit that referenced this pull request Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants