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

Reference to local file doesn't work #65

Closed
marcortw opened this issue Jun 12, 2019 · 7 comments
Closed

Reference to local file doesn't work #65

marcortw opened this issue Jun 12, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@marcortw
Copy link
Contributor

marcortw commented Jun 12, 2019

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

@fsimard-zz
Copy link

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:
...

@marcortw
Copy link
Contributor Author

@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.

@fmvilas
Copy link
Member

fmvilas commented Jun 18, 2019

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

@fmvilas fmvilas added the bug Something isn't working label Jun 18, 2019
@fsimard-zz
Copy link

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

@jtavares
Copy link

jtavares commented Jul 25, 2019

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.

@fmvilas
Copy link
Member

fmvilas commented Jul 26, 2019

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

@fmvilas
Copy link
Member

fmvilas commented Aug 21, 2019

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

@fmvilas fmvilas closed this as completed Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants