Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/fury-adapter-swagger/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Fury Swagger Parser Changelog

## 0.27.1 (2019-06-03)

### Bug Fixes

- Fixes a problem while parsing a document which contains a Swagger Schema for
a string which contains both a `minLength` and a `pattern` property which are
incompatible. For example, the following pattern: `^[A-z]*$` which is making
use of `*` which means that it allows strings that are zero length or more.
If there is a property `minLength` which is incompatible with the pattern
such as if `minLength` is set to 1. Previously this would cause the parser to
get into an infinite loop.

## 0.26.0 (2019-06-11)

### Breaking
Expand Down
9 changes: 9 additions & 0 deletions packages/fury-adapter-swagger/lib/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ const convertSubSchema = (schema, references, swagger) => {
actualSchema.type = 'string';
}

if (schema.pattern && schema.minLength && schema.pattern.startsWith('^[') && schema.pattern.endsWith(']*$')) {
// If a schema has a minimal length (minLength) > 0 AND there is a regex
// such as: `^[A-z]*$`, the schema can resolve to an empty string which
// doesn't match minLength.
//
// JSON Schema Faker will fail in that case and get into an infinite loop.
actualSchema.pattern = schema.pattern.replace('*$', '+$');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this replacing all occurrences of *$? From what I understand from this PR we should only modify the end.

Copy link
Member Author

Choose a reason for hiding this comment

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

$ refers to the end of the line in regex. So replacing *$ (usually would happen once at the end), if it is in the schema multiple times I think it should be fine to replace it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to make the modification closer to the invocation of that faker tool?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortuantely not, without copying every schema and traversing over it at the JSON Schema Faker entrypoint. I would like to avoid that, it would be a far more expensive operation.

}

if (schema.example) {
actualSchema.examples = [dereference(schema.example, swagger)];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fury-adapter-swagger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fury-adapter-swagger",
"version": "0.27.0",
"version": "0.27.1",
"description": "Swagger 2.0 parser for Fury.js",
"author": "Apiary.io <support@apiary.io>",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
{
"element": "parseResult",
"content": [
{
"element": "category",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "api"
}
]
},
"title": {
"element": "string",
"content": "Produces JSON with pattern"
}
},
"attributes": {
"version": {
"element": "string",
"content": "1.0"
}
},
"content": [
{
"element": "resource",
"attributes": {
"href": {
"element": "string",
"content": "/test"
}
},
"content": [
{
"element": "transition",
"content": [
{
"element": "httpTransaction",
"content": [
{
"element": "httpRequest",
"attributes": {
"method": {
"element": "string",
"content": "GET"
},
"headers": {
"element": "httpHeaders",
"content": [
{
"element": "member",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"attributes": {
"relation": {
"element": "string",
"content": "inferred"
},
"href": {
"element": "string",
"content": "http://docs.apiary.io/validations/swagger#produces-accept"
}
}
}
]
}
},
"content": {
"key": {
"element": "string",
"content": "Accept"
},
"value": {
"element": "string",
"content": "application/json"
}
}
}
]
}
}
},
{
"element": "httpResponse",
"attributes": {
"headers": {
"element": "httpHeaders",
"content": [
{
"element": "member",
"meta": {
"links": {
"element": "array",
"content": [
{
"element": "link",
"attributes": {
"relation": {
"element": "string",
"content": "inferred"
},
"href": {
"element": "string",
"content": "http://docs.apiary.io/validations/swagger#produces-content-type"
}
}
}
]
}
},
"content": {
"key": {
"element": "string",
"content": "Content-Type"
},
"value": {
"element": "string",
"content": "application/json"
}
}
}
]
},
"statusCode": {
"element": "string",
"content": "200"
}
},
"content": [
{
"element": "copy",
"content": "My Response"
},
{
"element": "asset",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "messageBody"
}
]
},
"links": {
"element": "array",
"content": [
{
"element": "link",
"attributes": {
"relation": {
"element": "string",
"content": "inferred"
},
"href": {
"element": "string",
"content": "http://docs.apiary.io/validations/swagger#message-body-generation"
}
}
}
]
}
},
"attributes": {
"contentType": {
"element": "string",
"content": "application/json"
}
},
"content": "A"
},
{
"element": "asset",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "messageBodySchema"
}
]
}
},
"attributes": {
"contentType": {
"element": "string",
"content": "application/schema+json"
}
},
"content": "{\"type\":\"string\",\"minLength\":1,\"maxLength\":255,\"pattern\":\"^[A-z]+$\"}"
},
{
"element": "dataStructure",
"content": {
"element": "string",
"meta": {
"description": {
"element": "string",
"content": "- Matches regex pattern: `^[A-z]*$`\n- Length of string must be less than, or equal to 255\n- Length of string must be greater than, or equal to 1"
}
}
}
}
]
}
]
}
]
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
swagger: '2.0'
info:
title: Produces JSON with pattern
version: '1.0'
produces:
- application/json
paths:
'/test':
get:
responses:
200:
description: 'My Response'
schema:
type: string
minLength: 1
maxLength: 255
pattern: ^[A-z]*$
2 changes: 1 addition & 1 deletion packages/fury-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"fury-adapter-apib-parser": "^0.16.0",
"fury-adapter-apib-serializer": "^0.12.0",
"fury-adapter-oas3-parser": "^0.9.0",
"fury-adapter-swagger": "^0.27.0",
"fury-adapter-swagger": "^0.27.1",
"js-yaml": "^3.12.0",
"minim": "^0.23.4"
},
Expand Down