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

Parsing error: Property assignment expected after updating Orval to 7.3.0 #1753

Closed
SHergibo opened this issue Dec 18, 2024 · 4 comments · Fixed by #1754
Closed

Parsing error: Property assignment expected after updating Orval to 7.3.0 #1753

SHergibo opened this issue Dec 18, 2024 · 4 comments · Fixed by #1754
Labels
mock Related to mock generation msw MSW related issues
Milestone

Comments

@SHergibo
Copy link

What are the steps to reproduce this issue?

  1. Use Orval 7.3.0
  2. Use the YAML reproduction provided in this PR
  3. Use Orval command to regenerate the files

YAML reproduction

openapi: '3.0.0'
info:
  version: 1.0.0
  title: example
  license:
    name: MIT
paths:
  /weight-measures:
    post:
      tags: ['BeneficiaryMeasures']
      operationId: createMeasureOfWeight
      summary: Record a weight measurement for the beneficiary.
      description: |-
        Save the weight with the author and datetime for the beneficiary 
        identified by the ref.
      x-with-target-resource: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/V2MeasureOfWeightRequest'
      responses:
        '201':
          description: The new measure has been recorded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2MeasureOfWeight'
          headers:
            Location:
              schema:
                type: string
              description: Relative URL to access this measure.
components:
  schemas:
    V2AbstractMeasureRequest:
      type: object
      properties:
        effectiveDateTime:
          type: string
          format: date-time
          example: '2020-04-25T23:40:50.52Z'

    V2MeasureOfWeightRequest:
      allOf:
        - $ref: '#/components/schemas/V2AbstractMeasureRequest'
        - type: object
          required:
            - value
          properties:
            value:
              type: object
              required:
                - weight
              properties:
                weight:
                  type: number
                  format: double
                  example: 83.5
                  minimum: 2.4
                  maximum: 500

    V2MeasureOfWeight:
      allOf:
        - $ref: '#/components/schemas/MeasureHref'
        - type: object
          required:
            - effectiveDateTime
            - value
          properties:
            effectiveDateTime:
              type: string
              format: date-time
              example: '2020-04-25T23:40:50.52Z'
            value:
              $ref: '#/components/schemas/MeasureOfWeight'

    MeasureOfWeight:
      type: object
      allOf:
        - $ref: '#/components/schemas/MeasureValue'
        - type: object
          required:
            - weight
          properties:
            weight:
              type: number
              format: double
              example: 83.5
              minimum: 2.4
              maximum: 500

    MeasureValue:
      type: object
      discriminator:
        propertyName: measureType
        mapping:
          Weight: '#/components/schemas/MeasureOfWeight'
      required:
        - measureType
      properties:
        measureType:
          $ref: '#/components/schemas/MeasureValueType'

    MeasureValueType:
      type: string
      enum:
        - Weight

    MeasureHref:
      type: object
      required: ['href']
      properties:
        href:
          type: string
          x-data-type: MeasureHrefValue
          example: '/v1/measures/f2584c95-7df7-4f02-8181-8d0f3547cb87'

What happens?

I received this error Parsing error: Property assignment expected for some of my .msw files.

export const getCreateMeasureOfWeightResponseMock = (): V2MeasureOfWeight => (
  {
    href: faker.string.alpha(20),
    effectiveDateTime: `${faker.date.past().toISOString().split('.')[0]}Z`, 
    value: {,weight: faker.number.float(),measureType: faker.helpers.arrayElement(['Weight'] as const)}
  }
)
Screenshot 2024-12-18 at 11 36 17

What were you expecting to happen?

The comma , before weight needs to be removed.

export const getCreateMeasureOfWeightResponseMock = (): V2MeasureOfWeight => (
  {
    href: faker.string.alpha(20),
    effectiveDateTime: `${faker.date.past().toISOString().split('.')[0]}Z`, 
    value: {weight: faker.number.float(),measureType: faker.helpers.arrayElement(['Weight'] as const)}
  }
)

Other comments

This YAML reproduction worked fine with orval 6.25.0.

What versions are you using?

  System:
    OS: macOS 15.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 148.96 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  npmPackages:
    axios: 1.7.9 => 1.7.9 
    msw: 2.7.0 => 2.7.0 
    orval: 7.3.0 => 7.3.0 
    react: 18.2.0 => 18.2.0 
@SHergibo
Copy link
Author

I also tried to update orval to 6.31.0 (from 6.25.0) and I have the same problem with this version.

@melloware melloware added msw MSW related issues mock Related to mock generation labels Dec 18, 2024
@melloware
Copy link
Collaborator

PR is welcome if you want to investigate!

@SHergibo
Copy link
Author

The bug was introduce in the version 6.29.0 of orval.

Before that version, orval generate this:


export const getCreateMeasureOfWeightResponseMock = (
  overrideResponse: any = {}
): V2MeasureOfWeight => ({
  href: faker.word.sample(),
  ...overrideResponse,
  effectiveDateTime: `${faker.date.past().toISOString().split('.')[0]}Z`,
  value: {
    ...overrideResponse,
    weight: faker.number.int({ max: 500, min: 2.4 }),
    ...overrideResponse,
    measureType: faker.helpers.arrayElement(['Weight'] as const),
    ...overrideResponse,
  },
  ...overrideResponse,
});

With version 6.29.0 and up I have:


export const getCreateMeasureOfWeightResponseMock = (): V2MeasureOfWeight => (
  {
    href: faker.string.alpha(20),
    effectiveDateTime: `${faker.date.past().toISOString().split('.')[0]}Z`, 
    value: {,weight: faker.number.float(),measureType: faker.helpers.arrayElement(['Weight'] as const)}
  }
)

The bug was maybe introduced by this PR: #1338

@melloware
Copy link
Collaborator

ahhh nice. If you can make a fix that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mock Related to mock generation msw MSW related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants