Generator: Reference to local file doesn't work

Created on 12 Jun 2019  Â·  7Comments  Â·  Source: asyncapi/generator

I am playing around with references to local files and can't get it to work with the generator and referencing a yaml file.

basic_example_refs.yml:

asyncapi: '2.0.0-rc1'
id: 'urn:array.example.com'

info:
  title: Very simple example
  version: '1.0.0'

channels:
  myChannel:
    publish:
      message:
        description: Simple example
        payload:
          $ref: './myObject.yml#/myObject'

components:
  schemas:
    myObject:
      type: object
      properties:
        key1:
          title: A key
          type: string
          default: "foo"
          enum:
            - foo
            - bar
          description: Just an example enum

myObject.yml:

myObject:
  type: object
  properties:
    key1:
      title: A key
      type: string
      default: "foo"
      enum:
        - foo
        - bar
      description: Just an example enum

Both are in the same directory. I am trying this on Windows. When doing this with the myObject.yml file, I get the following error:

C:\[...]\asyncapi-test\asyncapi-refs>ag basic_example_refs.yml html
2019/06/12 17:15:38 invalid character 'm' looking for beginning of value

After reading reusing messages, I thought that yaml files can be used. The 2.0.0-rc1 spec and this issue indicate that it might not be possible, though. However, when I am trying the same thing with a local json file, it works:

Changed basic_example_refs.yml:

        payload:
          $ref: './myObject.json#/myObject'

myObject.json:

{
  "myObject": {
    "type": "object",
    "properties": {
      "key1": {
        "title": "A key",
        "type": "string",
        "default": "foo",
        "enum": [
          "foo",
          "bar"
        ],
        "description": "Just an example enum"
      }
    }
  }
}

C:\[...]\asyncapi-test\asyncapi-refs>ag basic_example_refs.yml html
Done! ✨
Check out your shiny new generated files at C:\[...]\asyncapi-test\asyncapi-refs.

Is this an issue of the generator or am I doing something wrong here? Thanks in advance,
Marco

bug

All 7 comments

I am not sure its mandatory to have this structure. But this is how i make it work.

the reference should point to the type of object you want
$ref: 'myObject.yml#/components/schemas/myObject'

and inside the file myObject.yml

components:
  schemas:
    myObject:
...

@fsimard thanks for the hint, but that doesn't work for me. I always get invalid character 'c' looking for beginning of value even when I put a complete (and valid) asyncapi yaml doc inside of myObject.yml (asyncapi-generator 0.7.5).

After upgrading to 0.7.9 i get a slightly more expressive error message:
failed to process reference "myObject.yml#/components/schemas/myObject": invalid character 'a' looking for beginning of value. It says 'a' because with this run I even placed the asyncapi: '2.0.0-rc1' version string at the beginning of the file.

Mmm interesting. @xino12 can you have a look at this? Do you have an idea of why this is happening?

I upgrade to the last version and use 2.0.0-rc1 version using reference and I have the same problem

me, too :). I'm trying to include a yaml file by reference and fails with that message, where the offending character is the _first_ character of the included file. So, character 'a' is referring to the 'a' in 'asyncapi:' on the first line.

This bug is gonna get solved as soon as we release our new JS parser in the next weeks.

The generator is now using the new parser, which takes care of this. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

m-mohr picture m-mohr  Â·  7Comments

jonaslagoni picture jonaslagoni  Â·  4Comments

venth picture venth  Â·  5Comments

uraala picture uraala  Â·  10Comments

fmvilas picture fmvilas  Â·  8Comments