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

Using local artifactory with schemas causes some issues #917

Closed
derberg opened this issue Jan 10, 2024 · 6 comments
Closed

Using local artifactory with schemas causes some issues #917

derberg opened this issue Jan 10, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@derberg
Copy link
Member

derberg commented Jan 10, 2024

Describe the bug

I have such document

asyncapi: 3.0.0
info:
  title: User Signup API
  version: 1.0.0
  description: The API notifies you whenever a new user signs up in the application.
servers:
  kafkaServer:
    host: test.mykafkacluster.org:8092
    description: Kafka Server
    protocol: kafka
operations:
  onUserSignedUp:
    action: receive
    channel:
      $ref: '#/channels/userSignedUp'
channels:
  userSignedUp:
    description: This channel contains a message per each user who signs up in our application.
    address: user_signedup
    messages:
      userSignedUp:
        $ref: '#/components/messages/userSignedUp'
components:
  messages:
    userSignedUp:
      payload:
        schemaFormat: 'application/vnd.apache.avro+json;version=1.9.0'
        schema:
          $ref: http://localhost:8080/apis/registry/v2/groups/my-group/artifacts/UserSignedUp

And studio points strange issue in not existing line: 42:21 | TypeError: Failed to fetch

Yes, this is a valid link, I have this resource available. You can easily reproduce it.

Also when I try some different reference, pointing to https://www.asyncapi.com/resources/casestudies/adeo/CostingRequestPayload.avsc all is good. Like I don't know, like localhost is blocked or something

How to Reproduce

Terminal 1

Start artifactory docker run -it -p 8080:8080 apicurio/apicurio-registry-mem:2.5.8.Final

Terminal 2

upload schema

curl \
http://localhost:8080/apis/registry/v2/groups/my-group/artifacts \
-X POST  \
-H "Content-Type: application/json; artifactType=AVRO" \
-H "X-Registry-ArtifactId: UserSignedUp" \
--data @- << EOF
{
  "type": "record",
  "name": "UserSignedUp",
  "namespace": "com.company",
  "doc": "User sign-up information",
  "fields": [
    {
      "name": "userId",
      "type": "int"
    },
    {
      "name": "userEmail",
      "type": "string"
    }
  ]
}
EOF

and now you can access schema under: http://localhost:8080/apis/registry/v2/groups/my-group/artifacts/UserSignedUp

quickly checking curl http://localhost:8080/apis/registry/v2/groups/my-group/artifacts/UserSignedUp --verbose you can see server returns json with 200 like a charm

but yeah, when you put this link in $ref you get the same error as I described.


So I thought, maybe it is because of Apicurio, so this is how I confirmed that probably not

  1. installed this npm install -g http-server
  2. created a file with the avro schema mentioned above called dupa.avro
  3. started server and exposed directory with the file: http-server /folder/where/avrofile/located/
  4. took http://127.0.0.1:8080/dupa.avro and put in AsyncAPI document -> still the same error TypeError: Failed to fetch

So I do not think it is a problem of Apicurio sharing some wrong content type or something. Look like there is localhost issue?

@derberg derberg added the bug Something isn't working label Jan 10, 2024
@Amzani
Copy link
Collaborator

Amzani commented Jan 10, 2024

@derberg you are using a local studio instance to load your localhost schema ? or using https://studio.asyncapi.com/ ?

@ayush3160
Copy link

Hi @derberg @Amzani , I tried to reproduce the error using the http-server method but for me it is working fine. I have attached the screenshot , I think it might be a problem of CORS , Can you just try using --cors flag incase of http-server. Let me know If I am missing something would love to solve this bug if it is a bug.
Screenshot (66)

@derberg
Copy link
Member Author

derberg commented Jan 11, 2024

I'm using https://studio.asyncapi.com/

@derberg
Copy link
Member Author

derberg commented Jan 15, 2024

@ayush3160 but you did not reproduce my environment

  • you use studio on localhost, not studio.asyncapi.com
  • I cannot test quickly with localhost as I use AsyncAPI CLI, and it has super old version of studio
  • http-server by default runs with disabled cors, so adding --cors just breaks it even more
  • when I debug with http-server and add $ref to studio, there is no fetch request incoming to http-server
  • also strange that your $ref do not point to specific file

in inspect I see

Request URL:
http://127.0.0.1:8080/dupa.avro
Referrer Policy:
strict-origin-when-cross-origin

Assuming you use netlify, you could do https://github.com/asyncapi/website/blob/master/netlify.toml#L5

I'm pretty sure that it is CORS on netlify setting, as @ayush3160 proved it works fine on localhost from sources

@KhudaDad414
Copy link
Member

KhudaDad414 commented Jan 16, 2024

@derberg this is how I tried to replicate the issue and enabling CORS in both cases resolved the issues for me.

  • I am using studio.asyncapi.com
  1. With a bun server.

I used this file to create a server and studio.asyncapi.com seems to parse it correctly.

  1. With http-server

CORS was disabled by default for me so I had to enable it with --cors flag. after that, I put the schema.json file in the public folder and it seems to parse it correctly.

Screenshot 2024-01-16 at 11 24 56

this is my http-server log:

Screenshot 2024-01-16 at 11 33 13

shows an OPTIONS request. but it works fine.

@derberg
Copy link
Member Author

derberg commented Jan 17, 2024

omg it started working when I went into incognito...... 🤦🏼

normally console was showing Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
and by going to incognito all worked - so yeah some cache issue

now getting also nice error for apicurio:

studio.asyncapi.com/:1 Access to fetch at 'http://localhost:8080/apis/registry/v2/groups/my-group/artifacts/UserSignedUp' from origin 'https://studio.asyncapi.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

now I was able to dig in and find proper way to enable cors in apicurio: docker run --env CORS_ALLOWED_ORIGINS=* -it -p 8080:8080 apicurio/apicurio-registry-mem:2.5.8.Final

Thanks folks for helping 🙏🏼

@derberg derberg closed this as completed Jan 17, 2024
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

4 participants