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] Modelina is creating nested models for pattern properties #2034

Open
2 tasks done
Souvikns opened this issue Jun 11, 2024 · 1 comment
Open
2 tasks done

[BUG] Modelina is creating nested models for pattern properties #2034

Souvikns opened this issue Jun 11, 2024 · 1 comment
Labels
bug Something isn't working released on @next

Comments

@Souvikns
Copy link
Member

Describe the bug.

Modelina is creating nested properties for patternProperties.

Example scheme, I have tried to made it as small as possible to isolate the bug

{
  "type": "object",
  "patternProperties": {
    "^[\\w\\d\\.\\-_]+$": {
      "oneOf": [
        {
          "$ref": "#/definitions/Reference"
        },
        {
          "$ref": "#/definitions/messageObject"
        }
      ]
    }
  },
  "definitions": {
    "Reference": {
      "type": "object",
      "description": "A simple object to allow referencing other components in the specification, internally and externally.",
      "required": ["$ref"],
      "properties": {
        "$ref": {
          "description": "The reference string.",
          "$ref": "#/definitions/ReferenceObject"
        }
      },
      "examples": [
        {
          "$ref": "#/components/schemas/Pet"
        }
      ]
    },
    "ReferenceObject": {
      "type": "string",
      "format": "uri-reference"
    },
    "messageObject": {
      "type": "object",
      "description": "Describes a message received on a given channel and operation.",
      "additionalProperties": false,
      "properties": {
        "contentType": {
          "type": "string",
          "description": "The content type to use when encoding/decoding a message's payload. The value MUST be a specific media type (e.g. application/json). When omitted, the value MUST be the one specified on the defaultContentType field."
        }
      }
    }
  }
}

This scheme is generating this root object

package models

// Root represents a Root model.
type Root struct {
  ModelinaAnyType interface{}
  PatternProperty_0
}
// pattern_property_0.go
package models

// PatternProperty_0 represents a PatternProperty_0 model.
type PatternProperty_0 struct {
  Reference
  MessageObject
}

Expected behavior

Should not have ModelinaAnyType interface{} in the root object and use pattern_property_0 in root itsef.

Screenshots

Screenshot 2024-06-11 at 1 36 07 PM

I have pushed my code on github, if anyone wanna check it out https://github.com/Souvikns/modelina-bug

How to Reproduce

To reproduce this we have install "@asyncapi/modelina": "v4.0.0-next.45" and create a script to use go file generator to use GO_COMMON_PRESET.

import { GoFileGenerator, GO_COMMON_PRESET } from '@asyncapi/modelina'

import * as path from 'path'
import * as fs from 'fs'

async function defaultGenerateModels(input: any) {
  const generator = new GoFileGenerator({
    presets: [
      {
        preset: GO_COMMON_PRESET,
        options: {
          addJsonTag: true,
        },
      },
    ],
  })
  await generator.generateToFiles(input, './models', { packageName: 'models' })
}

async function generate() {
  const content = fs.readFileSync(path.resolve('./scheme.json'), 'utf-8')

  await defaultGenerateModels(JSON.parse(content))
}

generate().catch((e) => console.error(e))

installed

🥦 Browser

Mozilla Firefox

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

@Souvikns Souvikns added the bug Something isn't working label Jun 11, 2024
@Souvikns Souvikns changed the title [BUG] Modelina is creating nested models for patern properties [BUG] Modelina is creating nested models for pattern properties Jun 13, 2024
@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 4.0.0-next.50 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released on @next
Projects
None yet
Development

No branches or pull requests

2 participants