-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Fetching schema by url in library #34
Fetching schema by url in library #34
Conversation
… spec before validation it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff. I just left some comments. Keep up the great work 🙌
README.md
Outdated
@@ -45,6 +49,8 @@ The list of props for the AsyncApi React component includes: | |||
|
|||
> **NOTE:** The `Partial<T>` type means that every field in the `T` type is optional. | |||
|
|||
> **NOTE:** You must pass `schema` or `urlSchema` to component for correct work of component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about rewriting this copy?
Either schema
or urlSchema
prop must be present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kazydek must check this, but thank you for your proposition :)
@@ -98,6 +121,8 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncApiState> { | |||
|
|||
if (!(validatedSchema && validated)) return null; | |||
|
|||
console.log(validatedSchema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it forgotten here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah :D I always forget about console.logs in my code. Thanks!
@@ -53,12 +60,28 @@ class AsyncApiComponent extends Component<AsyncApiProps, AsyncApiState> { | |||
} | |||
|
|||
async componentWillMount() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up componentWillMount
is deprecated. Check out: https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
componentWillMount
and other will be deprecated on >= 17.0
versions. We use at the moment 16.6.3
version of React and we don't see any warnings related to the use of these lifecycles, but I will think whether to change it now or in the next PR.
@@ -16,7 +22,8 @@ import ErrorComponent from '../Error/Error'; | |||
import { AsyncApiWrapper } from './styled'; | |||
|
|||
export interface AsyncApiProps { | |||
schema: string | Object; | |||
schema?: string | Object; | |||
urlSchema?: FetchingSchemaInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we enforce that either schema or urlSchema must be provided? I know it's possible with prop-types, but not sure about Typescript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is possible by use type schema: string | Object | FetchingSchemaInterface
. If developer pass FetchingSchemaInterface then we will fetch schema from url, otherwise we use schema :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't explain myself correctly. I mean having both schema and urlSchema, like it's right now, but enforcing in the code the rule of having just one of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented my proposition from second comment in this thread. Please see: https://github.com/asyncapi/asyncapi-react/pull/34/files#diff-2fa873daa631d9246738398633704fd9R25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I love this solution. Just one question: I see it says string | Object | FetchSchemaInterface
, will it always fallback into Object
? Saying because an object of the form FetchSchemaInterface is also an object, right? Or will typescript take care of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :) You can pass schema as string (json or yaml), or Object (this is reference to AsyncAPIInterface) or FetchSchemaInterface. I agree with you that FetchSchemaInterface is also a Object, but Object with appropriate fields, so if dev pass Object as FetchSchemaInterface to component then component will execute whole code as FetchSchemaInterface, if pass as Object, then code validate this Object as AsyncApi and show errors if this spec is invalid :) You have to look at it in terms of static typing, not dynamic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. Thanks! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
README.md
Outdated
|
||
The `schema` property is required and contains AsyncAPI specification. It should be one of the `string` or [`AsyncApiInterface`](./library/src/types.ts#L13) type. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification). | ||
The `schema` property is required and contains AsyncAPI specification. It should be one of the `string` or [`AsyncApiInterface`](./library/src/types.ts#L13) type or [`FetchingSchemaInterface`](./library/src/helpers/fetchSchema.ts#L1) object for fetching schema from external resource. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `schema` property is required and contains AsyncAPI specification. It should be one of the `string` or [`AsyncApiInterface`](./library/src/types.ts#L13) type or [`FetchingSchemaInterface`](./library/src/helpers/fetchSchema.ts#L1) object for fetching schema from external resource. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification). | |
The `schema` property is required and contains AsyncAPI specification. Use the `string` type, the [`AsyncApiInterface`](./library/src/types.ts#L13) type, or the [`FetchingSchemaInterface`](./library/src/helpers/fetchSchema.ts#L1) object to fetch the schema from an external resource. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification). |
Description
Changes proposed in this pull request:
Related issue(s)
Resolves #32