|
1 |
| -// Copyright (c) Microsoft Corporation. All rights reserved. |
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
4 | 4 | using System;
|
@@ -465,164 +465,5 @@ private static OpenApiDocument CreateDocWithSimpleSchemaToInline()
|
465 | 465 |
|
466 | 466 | return doc;
|
467 | 467 | }
|
468 |
| - |
469 |
| - [Fact] |
470 |
| - |
471 |
| - public void WriteInlineRecursiveSchema() |
472 |
| - { |
473 |
| - // Arrange |
474 |
| - var doc = CreateDocWithRecursiveSchemaReference(); |
475 |
| - |
476 |
| - var expected = |
477 |
| -@"openapi: 3.0.1 |
478 |
| -info: |
479 |
| - title: Demo |
480 |
| - version: 1.0.0 |
481 |
| -paths: |
482 |
| - /: |
483 |
| - get: |
484 |
| - responses: |
485 |
| - '200': |
486 |
| - description: OK |
487 |
| - content: |
488 |
| - application/json: |
489 |
| - schema: |
490 |
| - type: object |
491 |
| - properties: |
492 |
| - children: |
493 |
| - $ref: '#/components/schemas/thing' |
494 |
| - related: |
495 |
| - type: integer |
496 |
| -components: |
497 |
| - schemas: |
498 |
| - thing: |
499 |
| - type: object |
500 |
| - properties: |
501 |
| - children: |
502 |
| - type: object |
503 |
| - properties: |
504 |
| - children: |
505 |
| - $ref: '#/components/schemas/thing' |
506 |
| - related: |
507 |
| - type: integer |
508 |
| - related: |
509 |
| - type: integer"; |
510 |
| - // Component schemas that are there due to cycles are still inlined because the items they reference may not exist in the components because they don't have cycles. |
511 |
| - |
512 |
| - var outputString = new StringWriter(CultureInfo.InvariantCulture); |
513 |
| - var writer = new OpenApiYamlWriter(outputString, new OpenApiWriterSettings { InlineLocalReferences = true }); |
514 |
| - |
515 |
| - // Act |
516 |
| - doc.SerializeAsV3(writer); |
517 |
| - var actual = outputString.GetStringBuilder().ToString(); |
518 |
| - |
519 |
| - // Assert |
520 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
521 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
522 |
| - actual.Should().BeEquivalentTo(expected); |
523 |
| - Assert.Equal(expected, actual); |
524 |
| - } |
525 |
| - |
526 |
| - private static OpenApiDocument CreateDocWithRecursiveSchemaReference() |
527 |
| - { |
528 |
| - var thingSchema = new JsonSchemaBuilder().Type(SchemaValueType.Object) |
529 |
| - .Ref("#/definitions/thing") |
530 |
| - .Properties( |
531 |
| - ("children", new JsonSchemaBuilder().Ref("#/definitions/thing")), |
532 |
| - ("related", new JsonSchemaBuilder().Type(SchemaValueType.Integer))) |
533 |
| - .Build(); |
534 |
| - |
535 |
| - var doc = new OpenApiDocument() |
536 |
| - { |
537 |
| - Info = new OpenApiInfo() |
538 |
| - { |
539 |
| - Title = "Demo", |
540 |
| - Version = "1.0.0" |
541 |
| - }, |
542 |
| - Paths = new OpenApiPaths() |
543 |
| - { |
544 |
| - ["/"] = new OpenApiPathItem |
545 |
| - { |
546 |
| - Operations = { |
547 |
| - [OperationType.Get] = new OpenApiOperation() { |
548 |
| - Responses = { |
549 |
| - ["200"] = new OpenApiResponse { |
550 |
| - Description = "OK", |
551 |
| - Content = { |
552 |
| - ["application/json"] = new OpenApiMediaType() { |
553 |
| - Schema = thingSchema |
554 |
| - } |
555 |
| - } |
556 |
| - } |
557 |
| - } |
558 |
| - } |
559 |
| - } |
560 |
| - } |
561 |
| - }, |
562 |
| - Components = new OpenApiComponents |
563 |
| - { |
564 |
| - Schemas = { |
565 |
| - ["thing"] = thingSchema} |
566 |
| - } |
567 |
| - }; |
568 |
| - |
569 |
| - return doc; |
570 |
| - } |
571 |
| - |
572 |
| - [Fact] |
573 |
| - public void WriteInlineRecursiveSchemav2() |
574 |
| - { |
575 |
| - // Arrange |
576 |
| - var doc = CreateDocWithRecursiveSchemaReference(); |
577 |
| - |
578 |
| - var expected = |
579 |
| -@"swagger: '2.0' |
580 |
| -info: |
581 |
| - title: Demo |
582 |
| - version: 1.0.0 |
583 |
| -paths: |
584 |
| - /: |
585 |
| - get: |
586 |
| - produces: |
587 |
| - - application/json |
588 |
| - responses: |
589 |
| - '200': |
590 |
| - description: OK |
591 |
| - schema: |
592 |
| - type: object |
593 |
| - properties: |
594 |
| - children: |
595 |
| - $ref: '#/definitions/thing' |
596 |
| - related: |
597 |
| - type: integer |
598 |
| -definitions: |
599 |
| - thing: |
600 |
| - type: object |
601 |
| - properties: |
602 |
| - children: |
603 |
| - type: object |
604 |
| - properties: |
605 |
| - children: |
606 |
| - $ref: '#/definitions/thing' |
607 |
| - related: |
608 |
| - type: integer |
609 |
| - related: |
610 |
| - type: integer"; |
611 |
| - // Component schemas that are there due to cycles are still inlined because the items they reference may not exist in the components because they don't have cycles. |
612 |
| - |
613 |
| - var outputString = new StringWriter(CultureInfo.InvariantCulture); |
614 |
| - var writer = new OpenApiYamlWriter(outputString, new OpenApiWriterSettings { InlineLocalReferences = true }); |
615 |
| - |
616 |
| - // Act |
617 |
| - doc.SerializeAsV2(writer); |
618 |
| - var actual = outputString.GetStringBuilder().ToString(); |
619 |
| - |
620 |
| - // Assert |
621 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
622 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
623 |
| - actual.Should().BeEquivalentTo(expected); |
624 |
| - Assert.Equal(expected, actual); |
625 |
| - } |
626 |
| - |
627 | 468 | }
|
628 | 469 | }
|
0 commit comments