Skip to content

feat: replace server url with server host and pathname - #888

Merged
asyncapi-bot merged 13 commits into
asyncapi:next-major-specfrom
fmvilas:fix-url-server-bug
Feb 13, 2023
Merged

asyncapi-bot merged 13 commits into
asyncapi:next-major-specfrom
fmvilas:fix-url-server-bug

Conversation

@fmvilas

@fmvilas fmvilas commented Dec 17, 2022

Copy link
Copy Markdown
Contributor

Fix bug with Server's URL field

Related issue(s):

#547
#274

@fmvilas fmvilas added the 💡 Proposal (RFC 1) RFC Stage 1 (See CONTRIBUTING.md) label Dec 17, 2022
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Comment thread spec/asyncapi.md
Comment on lines +482 to +514
##### Server Variable Object Example

```json
{
"servers": {
"production": {
"host": "{org}.mycompany.com",
"path": "/api/v1",
"description": "The production API server.",
"protocol": "https",
"variables": {
"org": {
"default": "demo",
"description": "This value is assigned by the service provider, in this example `mycompany.com`."
}
}
}
}
}
```

```yaml
servers:
production:
host: '{org}.mycompany.com'
path: '/api/v1'
description: The production API server.
protocol: https
variables:
org:
default: demo
description: This value is assigned by the service provider, in this example `mycompany.com`.
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added here Server Variable Object Example but that describes the whole Server Object, here only the:

        default: demo
        description: This value is assigned by the service provider, in this example `mycompany.com`.

should be written.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case it's justified to have the whole Server Object. Otherwise, there would be no context of where this demo variable is coming from.

Comment thread spec/asyncapi.md Resolved

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think title of PR should be more descriptive. Also PR should have short description so people do not have to read linked issues.

fix: rename server.url to server.host - something like that, to explain in one word what this change actually does, as later we use it in the change log

Comment thread spec/asyncapi.md Outdated
"servers": {
"production": {
"host": "{org}.mycompany.com",
"path": "/api/v1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path ? where is this coming from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were having a "URL" and now we have a host. A host does not have the "path" part so we have to add it separately.

@fmvilas fmvilas Dec 21, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other option is to remove the protocol field and go with a URL as we do now. Just not sure how this would play with protocols like kafka-secure (e.g., kafka-secure://hostname:port/path) and secure-mqtt (e.g., secure-mqtt://hostname:port/path), which are not "real" protocols. In such a case, we should probably get rid of the "secure" variants (that would include https and wss) and allow the user to specify it in the Security Requirement Object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we are actually fixing something, or making things a bit more complex. You add now path example that is a typical REST example for me. All the other examples I know (for example for Kafka) include a version in the topic name. In case of websocket it is completely fine to add path to channel name, but also if someone wants, can add it to url. The only use case for path that makes sense is HTTP, but then, if it is protocol specify, shouldn't it end up in the binding?

so basically my question is, do we really need to change url to host and path or, as majority of people in #274 wrote that we basically need to make description and examples better?

@fmvilas fmvilas Dec 22, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two things here:

  1. We often show examples where the url is "whatever.example.com". That's not a URL and that should fail because it doesn't have the protocol part of the URL (you know, protocol://).
  2. We have a field called protocol to define the protocol we want to use but it's already in the URL (!) ☝️ So you can end up with url: kafka://broker.mycompany.com and protocol: https in the same server definition, which is incongruent.

So we either remove the need to put a protocol in the url field (which makes it a host instead) or we remove the protocol field.

You add now path example that is a typical REST example for me.

I think you're mixing concepts here. A path is not about REST or not even HTTP. A path is a part of a URL. URLs are composed by protocol://, username:password (optional), hostname, port (optional), /path/to/resource (optional), ?query=parameters (optional), and #fragment (optional). These have nothing to do with REST or HTTP. I can have an AMQP broker at amqp://broker.mycompany.com/public and another one at amqp://broker.mycompany.com/partners. Depending on the path (public or partners), I'll reach one broker or another. This is actually a common pattern, BTW.

So what I'm doing here is making path optional (defaulting to / as it's assumed by the URL RFC). In the majority of cases, this path will not be needed but in some cases, it will. And yeah, especially in the case of HTTP and WS it's going to be needed but it's also frequent in AMQP and MQTT brokers.


So yeah, I took the approach to keep the protocol field and convert the url field to a host (hostname + port) one. Another approach is to remove protocol altogether as it's already in the URL field. A matter of preference, I guess.

so basically my question is, do we really need to change url to host and path or, as majority of people in #274 wrote that we basically need to make description and examples better?

We definitely have to improve the examples but this incongruency goes beyond showing examples or improving description.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well one thing is "concepts" and one thing is "just a simple association"

When I see

"host": "{org}.mycompany.com",
"path": "/api/v1",
"protocol": "https"

My brains says "REST". Then my brain also reminds me of AsyncAPI 1.0 and baseTopic. And then it tries to map it to concepts 😄 but yeah, enough with my brain 😄

Can we then improve the example and not put https protocol but something that will not cause brains to fart?
For example your amqp example. I guess there are different patterns, as I thought people prefer to split public/private or public/partners by host as then they do different authentication, rate limits and stuff like that. But yeah, it is flexible and people can do it as they wish.

or best would be to have 2 examples, one with path and one without it:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the origin of my question

path ? where is this coming from?

was that you use path but it is not described in the spec in your PR.

also side note: I think it should be pathname as we do not want to allow search (query params) here -> https://url.spec.whatwg.org/#dom-url-pathname

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we then improve the example and not put https protocol but something that will not cause brains to fart?

or best would be to have 2 examples, one with path and one without it:

Absolutely. I'll add two examples.

was that you use path but it is not described in the spec in your PR.

True. My fault. Adding it.

also side note: I think it should be pathname as we do not want to allow search (query params) here -> https://url.spec.whatwg.org/#dom-url-pathname

Good catch. Changing it 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derberg have a look again, please.

@fmvilas fmvilas changed the title fix: server url bug fix: replace server url with server host and path Dec 21, 2022
@fmvilas fmvilas changed the title fix: replace server url with server host and path fix: replace server url with server host and pathname Jan 17, 2023

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added one comment as I see your idea is that variables should be supported in pathname. Sounds good to me but we need an update.

Also, sorry if my previous comment sounded like I was suggesting that Gemini is a good example for pathname. I do not think it is, at least I modeled it differently in the official example -> https://github.com/asyncapi/spec/blob/a8c95348745dbeb5158f241f5b04ce7a1bbb6289/examples/websocket-gemini.yml

Comment thread spec/asyncapi.md Resolved
Co-authored-by: Lukasz Gornicki <[email protected]>
@fmvilas

fmvilas commented Jan 18, 2023

Copy link
Copy Markdown
Contributor Author

Also, sorry if my previous comment sounded like I was suggesting that Gemini is a good example for pathname. I do not think it is, at least I modeled it differently in the official example -> https://github.com/asyncapi/spec/blob/a8c95348745dbeb5158f241f5b04ce7a1bbb6289/examples/websocket-gemini.yml

I think it's still a good example. The difference is that you're defining the whole API and I'm just defining one endpoint 😄 But I get your point. Do you think we should change it to avoid confusions with your example?

@derberg

derberg commented Jan 20, 2023

Copy link
Copy Markdown
Member

@fmvilas yeah, I'm afraid that 2 examples contradict each other. Maybe add amqp samples you mentioned in the other comment, with public and private to something like that

@fmvilas

fmvilas commented Jan 23, 2023

Copy link
Copy Markdown
Contributor Author

@derberg I think examples are much better now. Have a look, please.

derberg
derberg previously approved these changes Feb 2, 2023

@derberg derberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@derberg

derberg commented Feb 2, 2023

Copy link
Copy Markdown
Member

I only think if it is really a fix, and not feat. In the end we have new fields, different new behaviour, so it is more an enhancement, new feature than fix

Comment thread spec/asyncapi.md Resolved
dalelane
dalelane previously approved these changes Feb 2, 2023

@dalelane dalelane left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the protocol versions in the Kafka examples aren't valid Kafka versions - so I've added a couple of suggested fixes to replace them with Kafka version numbers

but approving as they're only examples and not super critical

char0n
char0n previously approved these changes Feb 5, 2023

@char0n char0n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

The only issue I found is in here:

"url": "{stage}.gigantic-server.com:{port}",

Example is still using url field instead of new one.

Co-authored-by: Dale Lane <[email protected]>
@fmvilas
fmvilas dismissed stale reviews from char0n, dalelane, and derberg via 100d504 February 7, 2023 16:11
@fmvilas

fmvilas commented Feb 7, 2023

Copy link
Copy Markdown
Contributor Author

@derberg @dalelane @char0n @smoya would please review and approve again? 🙏

@magicmatatjahu

Copy link
Copy Markdown
Member

@fmvilas Do you want to add the json-schema changes yourself? I can help you :trollface:

@fmvilas

fmvilas commented Feb 8, 2023

Copy link
Copy Markdown
Contributor Author

@magicmatatjahu feel free mate! 😄

@magicmatatjahu

Copy link
Copy Markdown
Member

JSON Schema PR asyncapi/spec-json-schemas#329
ParserJS PR asyncapi/parser-js#708

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@fmvilas

fmvilas commented Feb 13, 2023

Copy link
Copy Markdown
Contributor Author

/rtm

@asyncapi-bot
asyncapi-bot merged commit a2fdc03 into asyncapi:next-major-spec Feb 13, 2023
@fmvilas
fmvilas deleted the fix-url-server-bug branch February 13, 2023 12:12
@asyncapi-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.0.0-next-major-spec.9 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants