├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.m2e.core.prefs ├── DEVELOPERS_GUIDE.md ├── GETTING_STARTED.md ├── License.txt ├── OPEN_API_V3_SUPPORT.md ├── README.md ├── TROUBLESHOOTING.md ├── com.reprezen.swagedit.core ├── .classpath ├── .project ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── icons │ ├── assist_item_16.png │ └── template_item_16.png ├── plugin.xml ├── pom.xml ├── resources │ ├── mediaTypes.json │ └── status-codes.json ├── schema │ ├── com.reprezen.swagedit.preferences.exsd │ ├── com.reprezen.swagedit.quickfix.exsd │ └── com.reprezen.swagedit.validator.exsd └── src │ └── com │ └── reprezen │ └── swagedit │ └── core │ ├── Activator.java │ ├── Messages.java │ ├── assist │ ├── JsonContentAssistProcessor.java │ ├── JsonProposalProvider.java │ ├── JsonQuickAssistProcessor.java │ ├── JsonReferenceProposalProvider.java │ ├── ProposalDescriptor.java │ ├── StyledCompletionProposal.java │ ├── StyledTemplateProposal.java │ ├── contexts │ │ ├── ComponentContextType.java │ │ ├── ContextType.java │ │ ├── ContextTypeCollection.java │ │ ├── RegexContextType.java │ │ └── SchemaContextType.java │ └── ext │ │ ├── ContentAssistExt.java │ │ ├── MediaTypeContentAssistExt.java │ │ └── ResponseCodeContentAssistExt.java │ ├── editor │ ├── JsonDocument.java │ ├── JsonDocumentProvider.java │ ├── JsonEditor.java │ ├── JsonReconcilingStrategy.java │ ├── JsonScanner.java │ ├── JsonSourceViewerConfiguration.java │ ├── TextContentDescriber.java │ ├── ValidationOperation.java │ ├── outline │ │ ├── JsonContentOutlinePage.java │ │ ├── OutlineContentProvider.java │ │ ├── OutlineStyledLabelProvider.java │ │ └── QuickOutline.java │ └── scanner │ │ ├── KeyRule.java │ │ └── PathRule.java │ ├── handlers │ └── OpenQuickOutlineHandler.java │ ├── hyperlinks │ ├── AbstractJsonHyperlinkDetector.java │ ├── DefinitionHyperlinkDetector.java │ ├── JsonFileHyperlink.java │ ├── JsonReferenceHyperlinkDetector.java │ ├── PathParamHyperlinkDetector.java │ ├── ReferenceHyperlinkDetector.java │ └── SwaggerHyperlink.java │ ├── json │ └── references │ │ ├── JsonDocumentManager.java │ │ ├── JsonReference.java │ │ ├── JsonReferenceCollector.java │ │ ├── JsonReferenceFactory.java │ │ ├── JsonReferenceValidator.java │ │ ├── Messages.java │ │ └── messages.properties │ ├── messages.properties │ ├── model │ ├── AbstractNode.java │ ├── ArrayNode.java │ ├── Location.java │ ├── Model.java │ ├── NodeDeserializer.java │ ├── ObjectNode.java │ └── ValueNode.java │ ├── preferences │ ├── JsonPreferenceInitializer.java │ ├── KaiZenPreferencesUtils.java │ ├── KaizenPreferencePage.java │ └── KaizenTemplatePreferences.java │ ├── providers │ ├── PreferenceProvider.java │ └── ValidationProvider.java │ ├── quickfix │ ├── QuickFixer.java │ └── TextDocumentMarkerResolution.java │ ├── schema │ ├── ArrayTypeDefinition.java │ ├── ComplexTypeDefinition.java │ ├── CompositeSchema.java │ ├── JsonSchema.java │ ├── JsonSchemaUtils.java │ ├── JsonType.java │ ├── MultipleTypeDefinition.java │ ├── ObjectTypeDefinition.java │ ├── ReferenceTypeDefinition.java │ └── TypeDefinition.java │ ├── templates │ ├── ElementNameResolver.java │ ├── SchemaBasedTemplateContextType.java │ └── SwaggerTemplateContext.java │ ├── utils │ ├── DocumentUtils.java │ ├── ExtensionUtils.java │ ├── StringUtils.java │ ├── SwaggerFileFinder.java │ └── URLUtils.java │ ├── validation │ ├── ErrorProcessor.java │ ├── JsonSchemaValidator.java │ ├── Markers.java │ ├── Messages.java │ ├── MultipleSwaggerErrorBuilder.java │ ├── SwaggerError.java │ ├── ValidationUtil.java │ ├── Validator.java │ ├── YamlErrorProcessor.java │ └── messages.properties │ └── wizard │ └── NewFileWizard.java ├── com.reprezen.swagedit.dependencies ├── META-INF │ └── MANIFEST.MF ├── build.properties └── pom.xml ├── com.reprezen.swagedit.feature ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.m2e.core.prefs ├── build.properties ├── feature.xml └── pom.xml ├── com.reprezen.swagedit.openapi3.tests ├── .classpath ├── .project ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── pom.xml ├── resources │ ├── code-assist │ │ ├── code-templates │ │ │ ├── CallbacksObject.yaml │ │ │ ├── HeadersObject.yaml │ │ │ ├── LinksObject.yaml │ │ │ ├── ParameterObject.yaml │ │ │ ├── RequestBody.yaml │ │ │ ├── ResponseObject.yaml │ │ │ ├── SchemaObject.yaml │ │ │ └── SecuitySchemesObject.yaml │ │ └── references │ │ │ ├── CallbacksObject.yaml │ │ │ ├── ExamplesObject.yaml │ │ │ ├── HeadersObject.yaml │ │ │ ├── LinksObject.yaml │ │ │ ├── Parameter.yaml │ │ │ ├── PathItem.yaml │ │ │ ├── RequestBody.yaml │ │ │ ├── ResponseObject.yaml │ │ │ ├── SchemaObject.yaml │ │ │ └── SecuitySchemesObject.yaml │ ├── spec_examples │ │ ├── spec │ │ │ └── schemas.yaml │ │ └── v3.0 │ │ │ ├── api-with-examples.yaml │ │ │ ├── callback-example.yaml │ │ │ ├── link-example.yaml │ │ │ ├── petstore-expanded.yaml │ │ │ ├── petstore.yaml │ │ │ └── uber.yaml │ └── tests │ │ └── validation_type.yaml └── src │ └── com │ └── reprezen │ └── swagedit │ └── openapi3 │ ├── assist │ ├── CodeAssistHelper.xtend │ ├── CodeTemplateContextTest.xtend │ ├── CodeTemplateTextTest.xtend │ ├── JsonReferenceProposalProvider_Quotes_Test.xtend │ ├── OpenApi3ContentAssistProcessorTest.xtend │ └── ReferenceContextTest.xtend │ ├── editor │ ├── OpenApi3ContentTypeTest.xtend │ └── hyperlinks │ │ └── HyperlinkDetectorTest.xtend │ ├── schema │ └── SchemaValidationTest.xtend │ ├── utils │ ├── Cursors.xtend │ └── Mocks.java │ └── validation │ ├── KaizenValidationTest.xtend │ ├── NullValueValidationTest.xtend │ ├── ReferenceValidatorTest.xtend │ ├── ValidationHelper.xtend │ └── ValidatorTest.xtend ├── com.reprezen.swagedit.openapi3 ├── .classpath ├── .project ├── META-INF │ └── MANIFEST.MF ├── OSGI-INF │ └── l10n │ │ └── bundle.properties ├── build.properties ├── icons │ ├── OpenAPI_16.png │ ├── OpenAPI_32.png │ └── OpenAPI_64.png ├── plugin.xml ├── pom.xml ├── resources │ ├── com.reprezen.swagedit.openapi3.xml │ ├── default.yaml │ └── templates.xml └── src │ └── com │ └── reprezen │ └── swagedit │ └── openapi3 │ ├── Activator.java │ ├── assist │ ├── OpenApi3ContentAssistProcessor.java │ ├── OpenApi3ReferenceProposalProvider.java │ ├── contexts │ │ ├── OperationContextType.java │ │ ├── OperationIdContextType.java │ │ └── SecuritySchemeContextType.java │ └── ext │ │ ├── CallbacksContentAssistExt.java │ │ ├── ParameterInContentAssistExt.java │ │ ├── SchemaFormatContentAssistExt.java │ │ └── SchemaTypeContentAssistExt.java │ ├── editor │ ├── OpenApi3ContentDescriber.java │ ├── OpenApi3Document.java │ ├── OpenApi3DocumentProvider.java │ ├── OpenApi3Editor.java │ └── wizard │ │ └── NewOpenApiV3SpecWizard.java │ ├── hyperlinks │ ├── LinkOperationHyperlinkDetector.java │ ├── LinkOperationRefHyperlinkDetector.java │ ├── OpenApi3FileHyperlink.java │ ├── OpenApi3ReferenceHyperlinkDetector.java │ └── SecuritySchemeHyperlinkDetector.java │ ├── preferences │ ├── OpenApi3PreferenceConstants.java │ ├── OpenApi3PreferenceInitializer.java │ ├── OpenApi3PreferencePage.java │ ├── OpenApi3ValidationPreferences.java │ ├── OpenApiColorPreferences.java │ └── OpenApiTemplatePreferences.java │ ├── schema │ ├── OpenApi3Schema.java │ ├── core.json │ └── schema_v3.json │ ├── templates │ └── OpenApi3ContextTypeProvider.java │ └── validation │ ├── OpenApi3ReferenceValidator.java │ └── OpenApi3Validator.java ├── com.reprezen.swagedit.repository ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.m2e.core.prefs ├── category.xml └── pom.xml ├── com.reprezen.swagedit.target ├── com.reprezen.swagedit.target.target └── pom.xml ├── com.reprezen.swagedit.tests ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── pom.xml ├── resources │ ├── error-1.json │ └── error-2.json └── src │ └── com │ └── reprezen │ └── swagedit │ ├── assist │ ├── JsonReferenceProposalProviderTest.xtend │ ├── SwaggerContentAssistProcessorTest.xtend │ └── SwaggerProposalProviderTest.xtend │ ├── editor │ ├── SwaggerDocumentTest.xtend │ ├── hyperlinks │ │ ├── DefinitionHyperlinkDetectorTest.xtend │ │ ├── JsonReferenceHyperlinkDetectorTest.xtend │ │ └── PathParamHyperlinkDetectorTest.xtend │ └── outline │ │ ├── AbstractNodeTest.xtend │ │ └── OutlineStyledLabelProviderTest.xtend │ ├── json │ └── references │ │ └── JsonReferenceFactoryTest.java │ ├── mocks │ └── Mocks.java │ ├── model │ └── ModelTest.xtend │ ├── schema │ └── SwaggerSchemaTest.xtend │ ├── templates │ └── CodeTemplateContextTest.java │ ├── tests │ ├── TestSuite.java │ └── utils │ │ ├── Cursors.xtend │ │ └── PointerHelpers.xtend │ └── validation │ ├── ErrorProcessorTest.java │ ├── MultipleSwaggerErrorMessageTest.xtend │ ├── NullValueValidationTest.xtend │ ├── ReferenceValidatorTest.xtend │ ├── ValidationMessageTest.xtend │ ├── ValidatorTest.xtend │ └── YamlErrorProcessorTest.xtend ├── com.reprezen.swagedit ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── META-INF │ └── MANIFEST.MF ├── OSGI-INF │ └── l10n │ │ └── bundle.properties ├── build.properties ├── icons │ ├── swagger_16.png │ ├── swagger_24.png │ ├── swagger_32.png │ └── swagger_64.png ├── plugin.xml ├── pom.xml ├── resources │ ├── com.reprezen.swagedit.xml │ ├── default.yaml │ └── templates.xml └── src │ └── com │ └── reprezen │ └── swagedit │ ├── Activator.java │ ├── Messages.java │ ├── assist │ ├── SwaggerContentAssistProcessor.java │ └── SwaggerReferenceProposalProvider.java │ ├── editor │ ├── SwaggerContentDescriber.java │ ├── SwaggerDocument.java │ ├── SwaggerDocumentProvider.java │ ├── SwaggerEditor.java │ ├── SwaggerReconcilingStrategy.java │ ├── SwaggerSourceViewerConfiguration.java │ └── hyperlinks │ │ └── SwaggerReferenceHyperlinkDetector.java │ ├── messages.properties │ ├── preferences │ ├── SwaggerColorPreferences.java │ ├── SwaggerPreferenceConstants.java │ ├── SwaggerPreferenceInitializer.java │ ├── SwaggerPreferencePage.java │ ├── SwaggerTemplatePreferences.java │ └── SwaggerValidationPreferences.java │ ├── schema │ ├── SwaggerSchema.java │ ├── core.json │ └── schema.json │ ├── templates │ └── SwaggerContextType.java │ ├── validation │ └── SwaggerValidator.java │ └── wizards │ ├── SwagEditNewWizard.java │ └── SwagEditNewWizardPage.java ├── etc ├── dev-env │ └── ModSquad_formatter_profile.xml └── img │ ├── ContentAssistQuickOutline.png │ ├── MacOS File New OpenAI 3 Crop.png │ ├── SwagEdit Graphics.pptx │ └── btn-install.png └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # maven build results 15 | target/ 16 | lib/ 17 | 18 | # Xtend Gen folder 19 | xtend-gen/ 20 | 21 | # Eclipse 22 | .classpath 23 | .project 24 | .settings 25 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | SwagEdit 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /GETTING_STARTED.md: -------------------------------------------------------------------------------- 1 | ## Installing KaiZen OpenAPI Editor 2 | Follow instructions from the [README File](https://github.com/RepreZen/KaiZen-OpenAPI-Editor#user-content-installing-kaizen-openapi-editor). 3 | 4 | ## Creating an OpenAPI Spec 5 | 1. Open a list of the available creation wizards: **File > New > Other...** .

6 | 2. Expand the **KaiZen OpenAPI Editor** category.

File>New>Other KaiZen OpenAPI Editor Category

7 | 3. Choose one of the available options:

8 | * Choose **Swagger v2 Spec** to create a Swagger-OpenAPI 2.0 specification. This is the current industry-standard API description language, supported by thousands of open source projects and all major API technology vendors.

9 | * Choose **OpenAPI v3 Spec** to create an OpenAPI 3.0 specification. This is the first major upgrade to OAS, scheduled for a final release in July 2017. See [OpenAPI 3.0 Editing Support](OPEN_API_V3_SUPPORT.md) for more information on current and planned features. 10 |     11 | 12 | 13 | -------------------------------------------------------------------------------- /OPEN_API_V3_SUPPORT.md: -------------------------------------------------------------------------------- 1 | # NEW! Full OpenAPI 3.0 Editing Support 2 | We are really pleased to inform you that KaiZen OpenAPI Editor now fully supports the [OpenAPI 3.0 specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md). Here's some of the cool stuff that you can now do with OpenAPI v3 specs: 3 | 4 | ## Validation 5 | Validation: invalid 'kind' property 6 | 7 | ## Content Assist 8 | Content Assist 9 | 10 | ## Quick Outline 11 | Quick Outline 12 | 13 | ## Outline 14 | Outline 15 | 16 | # FAQ 17 | ## How do I create a new OpenAPI v3 spec? 18 | Please use the *OpenAPI v3 Spec* wizard from the *KaiZen OpenAPI Editor* category: 19 | 20 | 21 | File>New>Other KaiZen OpenAPI Editor Category 22 | 23 | ## The editor for Swagger v2 uses an underlying JSON Schema. There's no official JSON Schema for OpenAPI v3, so what are you using? 24 | We use a modification of the JSON Schema provided by [googleapis/gnostic](https://github.com/googleapis/gnostic). We use the [SwagEdit branch](https://github.com/RepreZen/gnostic/tree/SwagEdit) to generate our JSON Schema. Thanks to @timburks and @MikeRalphson for the contribution! 25 | 26 | -------------------------------------------------------------------------------- /TROUBLESHOOTING.md: -------------------------------------------------------------------------------- 1 | ## Autoformat (Ctrl+Shift+F) removes YAML comments 2 | This is a [known issue](https://github.com/oyse/yedit/issues/15) of YEdit, the YAML Editor on which KaiZen OpenAPI Editor is built. There is no fix for this yet, so we recommend that you disable the key binding for YEdit in Eclipse Preferences: 3 | yedit_disableformat 4 | 5 | 1. Open the "General > Keys" page. 6 | 2. Type "format" in the search box. 7 | 3. Select the command from the YEdit category. 8 | 4. Click the "Unbind Command" button. 9 | 5. Confirm by selecting "OK". 10 | 11 | ## Handling special (non-UTF) characters 12 | JSON does not support non UTF encoding, so for now we recommend avoid using special characters, e.g. accented letters, in your Swagger specification. See [issue 158](https://github.com/RepreZen/SwagEdit/issues/158) for details 13 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.reprezen.swagedit.core 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.xtext.ui.shared.xtextNature 36 | org.eclipse.m2e.core.maven2Nature 37 | org.eclipse.pde.PluginNature 38 | org.eclipse.jdt.core.javanature 39 | 40 | 41 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: KaiZen OpenAPI Editor Core Plugin 4 | Bundle-SymbolicName: com.reprezen.swagedit.core;singleton:=true 5 | Bundle-Version: 0.8.0.qualifier 6 | Bundle-Vendor: ModelSolv, Inc. d.b.a. RepreZen 7 | Require-Bundle: org.eclipse.ui, 8 | org.eclipse.core.runtime, 9 | org.eclipse.e4.core.di, 10 | org.eclipse.ui.editors, 11 | org.eclipse.jface.text, 12 | org.dadacoalition.yedit, 13 | org.eclipse.core.resources, 14 | org.eclipse.ui.ide, 15 | org.eclipse.core.filesystem, 16 | org.eclipse.ui.workbench.texteditor, 17 | org.eclipse.ui.views, 18 | org.apache.commons.lang3;bundle-version="3.1.0", 19 | com.reprezen.swagedit.dependencies;bundle-version="0.8.0" 20 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 21 | Bundle-ActivationPolicy: lazy 22 | Export-Package: com.reprezen.swagedit.core, 23 | com.reprezen.swagedit.core.assist, 24 | com.reprezen.swagedit.core.assist.contexts, 25 | com.reprezen.swagedit.core.assist.ext, 26 | com.reprezen.swagedit.core.editor, 27 | com.reprezen.swagedit.core.editor.outline, 28 | com.reprezen.swagedit.core.editor.scanner, 29 | com.reprezen.swagedit.core.handlers, 30 | com.reprezen.swagedit.core.hyperlinks, 31 | com.reprezen.swagedit.core.json.references, 32 | com.reprezen.swagedit.core.model, 33 | com.reprezen.swagedit.core.preferences, 34 | com.reprezen.swagedit.core.providers, 35 | com.reprezen.swagedit.core.quickfix, 36 | com.reprezen.swagedit.core.schema, 37 | com.reprezen.swagedit.core.templates, 38 | com.reprezen.swagedit.core.utils, 39 | com.reprezen.swagedit.core.validation, 40 | com.reprezen.swagedit.core.wizard 41 | Bundle-Activator: com.reprezen.swagedit.core.Activator 42 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = target/classes/ 3 | bin.includes = .,\ 4 | META-INF/,\ 5 | icons/,\ 6 | plugin.xml,\ 7 | resources/,\ 8 | schema/ 9 | jars.compile.order = . 10 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/icons/assist_item_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit.core/icons/assist_item_16.png -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/icons/template_item_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit.core/icons/template_item_16.png -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 12 | 13 | 14 | 15 | 17 | 21 | 22 | 23 | 24 | 26 | 31 | 32 | 33 | 34 | 36 | 41 | 42 | 43 | 44 | 45 | 48 | 49 | 51 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.reprezen.swagedit.core 4 | 5 | 6 | com.reprezen 7 | SwagEdit 8 | 0.8.0-SNAPSHOT 9 | ../pom.xml 10 | 11 | 12 | eclipse-plugin 13 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/resources/mediaTypes.json: -------------------------------------------------------------------------------- 1 | [ 2 | "'*/*'", 3 | "application/*", 4 | "application/atom+xml", 5 | "application/binary", 6 | "application/epub+zip", 7 | "application/javascript", 8 | "application/json", 9 | "application/mbox", 10 | "application/msword", 11 | "application/octet-stream", 12 | "application/ogg", 13 | "application/pdf", 14 | "application/pkcs12", 15 | "application/postscript", 16 | "application/protobuf", 17 | "application/rdf+xml", 18 | "application/rtf", 19 | "application/vnd.google-earth.kml+xml", 20 | "application/vnd.google-earth.kmz", 21 | "application/vnd.ms-excel", 22 | "application/vnd.ms-powerpoint", 23 | "application/vnd.oasis.opendocument.graphics", 24 | "application/vnd.oasis.opendocument.presentation", 25 | "application/vnd.oasis.opendocument.spreadsheet", 26 | "application/vnd.oasis.opendocument.text", 27 | "application/vnd.openxmlformats-officedocument.presentationml.presentation", 28 | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 29 | "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 30 | "application/vnd.sketchup.skp", 31 | "application/x-bzip2", 32 | "application/x-gzip", 33 | "application/x-shockwave-flash", 34 | "application/x-tar", 35 | "application/x-www-form-urlencoded", 36 | "application/xhtml+xml", 37 | "application/xml", 38 | "application/xrd+xml", 39 | "application/zip", 40 | "audio/*", 41 | "audio/mp4", 42 | "audio/mpeg", 43 | "audio/ogg", 44 | "audio/webm", 45 | "image/*", 46 | "image/bmp", 47 | "image/gif", 48 | "image/jpeg", 49 | "image/png", 50 | "image/svg+xml", 51 | "image/tiff", 52 | "image/vnd.adobe.photoshop", 53 | "image/vnd.microsoft.icon", 54 | "image/webp", 55 | "image/x-canon-crw", 56 | "text/*", 57 | "text/cache-manifest", 58 | "text/calendar", 59 | "text/css", 60 | "text/csv", 61 | "text/html", 62 | "text/javascript", 63 | "text/plain", 64 | "text/tab-separated-values", 65 | "text/vcard", 66 | "text/vnd.wap.wml", 67 | "text/xml", 68 | "video/*", 69 | "video/mp4", 70 | "video/mpeg", 71 | "video/ogg", 72 | "video/quicktime", 73 | "video/webm", 74 | "video/x-ms-wmv" 75 | ] -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/Messages.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core; 12 | 13 | import org.eclipse.osgi.util.NLS; 14 | 15 | public class Messages extends NLS { 16 | 17 | private static final String BUNDLE_NAME = "com.reprezen.swagedit.core.messages"; 18 | 19 | public static String outline_proposal_local; 20 | public static String outline_proposal_project; 21 | public static String outline_proposal_workspace; 22 | 23 | static { 24 | NLS.initializeMessages(BUNDLE_NAME, Messages.class); 25 | } 26 | 27 | private Messages() { 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/assist/StyledTemplateProposal.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.assist; 12 | 13 | import org.eclipse.jface.text.IRegion; 14 | import org.eclipse.jface.text.contentassist.ICompletionProposalExtension6; 15 | import org.eclipse.jface.text.templates.Template; 16 | import org.eclipse.jface.text.templates.TemplateContext; 17 | import org.eclipse.jface.text.templates.TemplateProposal; 18 | import org.eclipse.jface.viewers.StyledString; 19 | import org.eclipse.swt.graphics.Image; 20 | 21 | public class StyledTemplateProposal extends TemplateProposal implements ICompletionProposalExtension6 { 22 | 23 | private StyledString styledString; 24 | 25 | public StyledTemplateProposal(Template template, TemplateContext context, IRegion region, Image image, 26 | StyledString styledString, int relevance) { 27 | super(template, context, region, image, relevance); 28 | this.styledString = styledString; 29 | } 30 | 31 | @Override 32 | public StyledString getStyledDisplayString() { 33 | return styledString; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/assist/contexts/ContextTypeCollection.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.assist.contexts; 12 | import com.fasterxml.jackson.core.JsonPointer; 13 | import com.reprezen.swagedit.core.model.Model; 14 | 15 | public class ContextTypeCollection { 16 | 17 | private final Iterable contextTypes; 18 | 19 | protected ContextTypeCollection(Iterable contextTypes) { 20 | this.contextTypes = contextTypes; 21 | } 22 | 23 | public ContextType get(Model model, JsonPointer pointer) { 24 | for (ContextType next : contextTypes) { 25 | if (next.canProvideProposal(model, pointer)) { 26 | return next; 27 | } 28 | } 29 | return ContextType.UNKNOWN; 30 | } 31 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/assist/contexts/RegexContextType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.assist.contexts; 12 | 13 | import com.fasterxml.jackson.core.JsonPointer; 14 | import com.reprezen.swagedit.core.model.Model; 15 | 16 | /** 17 | * 18 | * The context type is determined by the pointer (path) on which the completion proposal has been activated. 19 | */ 20 | public class RegexContextType extends ContextType { 21 | 22 | private final String regex; 23 | 24 | public RegexContextType(String value, String label, String regex) { 25 | super(value, label); 26 | this.regex = regex; 27 | } 28 | 29 | public RegexContextType(String value, String label, String regex, boolean isLocalOnly) { 30 | super(value, label, isLocalOnly); 31 | this.regex = regex; 32 | } 33 | 34 | public boolean canProvideProposal(Model model, JsonPointer pointer) { 35 | if (pointer != null && regex != null) { 36 | return pointer.toString().matches(regex); 37 | } 38 | return false; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/assist/contexts/SchemaContextType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.assist.contexts; 12 | 13 | import java.util.Collection; 14 | 15 | import org.eclipse.core.runtime.IPath; 16 | 17 | import com.fasterxml.jackson.databind.JsonNode; 18 | import com.reprezen.swagedit.core.assist.ProposalDescriptor; 19 | import com.reprezen.swagedit.core.editor.JsonDocument; 20 | import com.reprezen.swagedit.core.model.Model; 21 | import com.reprezen.swagedit.core.schema.CompositeSchema; 22 | 23 | public abstract class SchemaContextType extends RegexContextType { 24 | 25 | private final CompositeSchema schema; 26 | 27 | public SchemaContextType(CompositeSchema schema, String value, String label, String regex) { 28 | this(schema, value, label, regex, false); 29 | } 30 | 31 | public SchemaContextType(CompositeSchema schema, String value, String label, String regex, boolean isLocalOnly) { 32 | super(value, label, regex, isLocalOnly); 33 | 34 | this.schema = schema; 35 | } 36 | 37 | public CompositeSchema getSchema() { 38 | return schema; 39 | } 40 | 41 | @Override 42 | public Collection collectProposals(JsonDocument document, IPath path) { 43 | return collectProposals(document.getModel(), path); 44 | } 45 | 46 | @Override 47 | public Collection collectProposals(JsonNode document, IPath path) { 48 | return collectProposals(Model.parse(getSchema(), document), path); 49 | } 50 | 51 | public abstract Collection collectProposals(Model parse, IPath path); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/assist/ext/ContentAssistExt.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.assist.ext; 12 | 13 | import java.util.Collection; 14 | 15 | import com.reprezen.swagedit.core.assist.ProposalDescriptor; 16 | import com.reprezen.swagedit.core.model.AbstractNode; 17 | import com.reprezen.swagedit.core.schema.TypeDefinition; 18 | 19 | /** 20 | * Implementation of this interface can be used to provide additional completion proposals that cannot be extracted from 21 | * a JSON schema. 22 | */ 23 | public interface ContentAssistExt { 24 | 25 | /** 26 | * Returns true if this extension can be used to provide proposals for the given type definition. 27 | * 28 | * @param type 29 | * @return true if proposals 30 | */ 31 | boolean canProvideContentAssist(TypeDefinition type); 32 | 33 | /** 34 | * Returns a collection of prposals 35 | * 36 | * @param type 37 | * @param node 38 | * @param prefix 39 | * @return proposals 40 | */ 41 | Collection getProposals(TypeDefinition type, AbstractNode node, String prefix); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/editor/JsonDocumentProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.editor; 12 | 13 | import java.util.Set; 14 | 15 | import org.dadacoalition.yedit.editor.ColorManager; 16 | import org.dadacoalition.yedit.editor.scanner.YAMLToken; 17 | import org.eclipse.core.runtime.CoreException; 18 | import org.eclipse.jface.preference.IPreferenceStore; 19 | import org.eclipse.jface.text.IDocument; 20 | import org.eclipse.jface.text.rules.FastPartitioner; 21 | import org.eclipse.ui.editors.text.FileDocumentProvider; 22 | 23 | public abstract class JsonDocumentProvider extends FileDocumentProvider { 24 | 25 | private final IPreferenceStore store; 26 | 27 | protected abstract IDocument createEmptyDocument(); 28 | 29 | public JsonDocumentProvider(IPreferenceStore store) { 30 | this.store = store; 31 | } 32 | 33 | @Override 34 | protected IDocument createDocument(Object element) throws CoreException { 35 | IDocument document = super.createDocument(element); 36 | if (document != null) { 37 | JsonScanner scanner = new JsonScanner(new ColorManager(), store); 38 | Set tokens = YAMLToken.VALID_TOKENS.keySet(); 39 | FastPartitioner partitioner = new FastPartitioner(scanner, tokens.toArray(new String[tokens.size()])); 40 | document.setDocumentPartitioner(partitioner); 41 | partitioner.connect(document); 42 | } 43 | 44 | return document; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/editor/TextContentDescriber.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.editor; 12 | 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | 16 | import org.eclipse.core.runtime.QualifiedName; 17 | import org.eclipse.core.runtime.content.IContentDescriber; 18 | import org.eclipse.core.runtime.content.IContentDescription; 19 | 20 | import com.reprezen.swagedit.core.utils.StringUtils; 21 | 22 | public abstract class TextContentDescriber implements IContentDescriber { 23 | 24 | protected abstract boolean isSupported(String contentsAsText); 25 | 26 | @Override 27 | public int describe(InputStream contents, IContentDescription description) throws IOException { 28 | String content = StringUtils.toString(contents); 29 | if (content.trim().isEmpty()) { 30 | return INDETERMINATE; 31 | } 32 | 33 | return isSupported(content) ? VALID : INVALID; 34 | } 35 | 36 | @Override 37 | public QualifiedName[] getSupportedOptions() { 38 | return null; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/editor/scanner/KeyRule.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.editor.scanner; 12 | 13 | import org.eclipse.jface.text.rules.IToken; 14 | 15 | /** 16 | * Scanner rule for matching keys in a mapping. 17 | * 18 | * This rule is based on YEdit KeyRule but uses a different regex that allows slash and dollar sign. It is necessary to 19 | * allow media types such as `application/json` and references `$ref` as keys. 20 | */ 21 | public class KeyRule extends org.dadacoalition.yedit.editor.scanner.KeyRule { 22 | 23 | public KeyRule(IToken token) { 24 | super(token); 25 | } 26 | 27 | protected String getKeyRegex() { 28 | return "([\\w \\- _ + $] [\\w \\s \\. \\\\ \\- _ + /]*:)\\s.*"; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/editor/scanner/PathRule.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.editor.scanner; 12 | 13 | import org.eclipse.jface.text.rules.IToken; 14 | 15 | /** 16 | * Scanner rule for matching keys that are paths (starting with /). 17 | */ 18 | public class PathRule extends KeyRule { 19 | 20 | public PathRule(IToken token) { 21 | super(token); 22 | } 23 | 24 | @Override 25 | protected String getKeyRegex() { 26 | return "([/] [\\w \\s \\. \\\\ \\- _ + / { }]*:)\\s.*"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/handlers/OpenQuickOutlineHandler.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.handlers; 12 | 13 | import org.eclipse.core.commands.AbstractHandler; 14 | import org.eclipse.core.commands.ExecutionEvent; 15 | import org.eclipse.core.commands.ExecutionException; 16 | import org.eclipse.jface.text.ITextOperationTarget; 17 | import org.eclipse.jface.text.source.ISourceViewer; 18 | import org.eclipse.swt.widgets.Control; 19 | import org.eclipse.ui.IEditorPart; 20 | import org.eclipse.ui.handlers.HandlerUtil; 21 | 22 | import com.reprezen.swagedit.core.editor.JsonEditor; 23 | 24 | public class OpenQuickOutlineHandler extends AbstractHandler { 25 | 26 | public static final int QUICK_OUTLINE = 513; // magic number from PDE quick outline see PDEProjectionViewer 27 | 28 | @Override 29 | public Object execute(ExecutionEvent event) throws ExecutionException { 30 | ISourceViewer viewer = null; 31 | 32 | Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl"); //$NON-NLS-1$ 33 | if (activeFocusControl instanceof Control) { 34 | Control control = (Control) activeFocusControl; 35 | if (!control.isDisposed()) { 36 | viewer = (ISourceViewer) control.getData(ISourceViewer.class.getName()); 37 | } 38 | } 39 | 40 | if (viewer == null) { 41 | IEditorPart editor = HandlerUtil.getActiveEditor(event); 42 | if (editor instanceof JsonEditor) { 43 | viewer = ((JsonEditor) editor).getProjectionViewer(); 44 | } 45 | } 46 | 47 | if (viewer != null) { 48 | ITextOperationTarget operationTarget = viewer.getTextOperationTarget(); 49 | if (operationTarget.canDoOperation(QUICK_OUTLINE)) { 50 | operationTarget.doOperation(QUICK_OUTLINE); 51 | } 52 | } 53 | 54 | return null; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/hyperlinks/JsonFileHyperlink.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.hyperlinks; 12 | 13 | import java.io.IOException; 14 | 15 | import org.eclipse.core.resources.IFile; 16 | import org.eclipse.core.runtime.CoreException; 17 | import org.eclipse.jface.text.IRegion; 18 | import org.eclipse.jface.text.hyperlink.IHyperlink; 19 | 20 | import com.fasterxml.jackson.core.JsonPointer; 21 | import com.reprezen.swagedit.core.editor.JsonDocument; 22 | import com.reprezen.swagedit.core.utils.DocumentUtils; 23 | 24 | public abstract class JsonFileHyperlink implements IHyperlink { 25 | 26 | private final IRegion linkRegion; 27 | private final String label; 28 | private final IFile file; 29 | private final JsonPointer pointer; 30 | 31 | public JsonFileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) { 32 | this.linkRegion = linkRegion; 33 | this.label = label; 34 | this.file = file; 35 | this.pointer = pointer; 36 | } 37 | 38 | protected abstract JsonDocument createDocument(); 39 | 40 | @Override 41 | public IRegion getHyperlinkRegion() { 42 | return linkRegion; 43 | } 44 | 45 | @Override 46 | public String getTypeLabel() { 47 | return label; 48 | } 49 | 50 | @Override 51 | public String getHyperlinkText() { 52 | return label; 53 | } 54 | 55 | @Override 56 | public void open() { 57 | if (file == null || !file.exists()) { 58 | return; 59 | } 60 | 61 | try { 62 | DocumentUtils.openAndReveal(file, getTarget()); 63 | } catch (Exception e) { 64 | // TODO 65 | } 66 | } 67 | 68 | private IRegion getTarget() throws CoreException { 69 | JsonDocument doc = null; 70 | try { 71 | String content = DocumentUtils.getDocumentContent(file.getLocation()); 72 | doc = createDocument(); 73 | doc.set(content); 74 | } catch (IOException e) { 75 | return null; 76 | } 77 | return doc.getRegion(pointer); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/hyperlinks/JsonReferenceHyperlinkDetector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.hyperlinks; 12 | 13 | import org.eclipse.core.resources.IFile; 14 | import org.eclipse.jface.text.IRegion; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | 18 | /** 19 | * Hyperlink detector that detects links from JSON references. 20 | */ 21 | public abstract class JsonReferenceHyperlinkDetector extends ReferenceHyperlinkDetector { 22 | 23 | @Override 24 | protected JsonFileHyperlink createFileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) { 25 | // TODO Auto-generated method stub 26 | return null; 27 | } 28 | 29 | @Override 30 | protected boolean canDetect(JsonPointer pointer) { 31 | return pointer != null && pointer.toString().endsWith("$ref"); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/json/references/JsonReferenceCollector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.json.references; 12 | 13 | import static com.reprezen.swagedit.core.json.references.JsonReference.PROPERTY; 14 | 15 | import java.net.URI; 16 | import java.util.ArrayList; 17 | import java.util.HashMap; 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import com.reprezen.swagedit.core.model.AbstractNode; 22 | import com.reprezen.swagedit.core.model.Model; 23 | 24 | /** 25 | * Collector of JSON references present in a JSON or YAML document. 26 | * 27 | * This class can be used to obtain all JSONReference present inside a JSON or YAML document. 28 | * 29 | */ 30 | public class JsonReferenceCollector { 31 | 32 | private final JsonReferenceFactory factory; 33 | 34 | public JsonReferenceCollector(JsonReferenceFactory factory) { 35 | this.factory = factory; 36 | } 37 | 38 | /** 39 | * Returns all reference nodes that can be found in the JSON document. 40 | * 41 | * @param baseURI 42 | * @param model 43 | * @return all reference nodes 44 | */ 45 | public Map> collect(URI baseURI, Model model) { 46 | final Map> references = new HashMap<>(); 47 | 48 | for (AbstractNode node : model.allNodes()) { 49 | if (factory.isReference(node)) { 50 | JsonReference reference = factory.createSimpleReference(baseURI, node.get(PROPERTY)); 51 | if (reference == null) { 52 | reference = factory.create(node); 53 | } 54 | 55 | if (reference != null) { 56 | if (references.containsKey(reference)) { 57 | references.get(reference).add(node); 58 | } else { 59 | List values = new ArrayList<>(); 60 | values.add(node); 61 | 62 | references.put(reference, values); 63 | } 64 | } 65 | } 66 | } 67 | 68 | return references; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/json/references/Messages.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.json.references; 12 | 13 | import org.eclipse.osgi.util.NLS; 14 | 15 | public class Messages extends NLS { 16 | 17 | private static final String BUNDLE_NAME = "com.reprezen.swagedit.core.json.references.messages"; 18 | 19 | public static String error_missing_reference; 20 | public static String error_invalid_reference; 21 | 22 | public static String warning_simple_reference; 23 | 24 | public static String content_assist_proposal_local; 25 | public static String content_assist_proposal_project; 26 | public static String content_assist_proposal_workspace; 27 | 28 | static { 29 | NLS.initializeMessages(BUNDLE_NAME, Messages.class); 30 | } 31 | 32 | private Messages() { 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/json/references/messages.properties: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (c) 2016 ModelSolv, Inc. and others. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the Eclipse Public License v1.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.eclipse.org/legal/epl-v10.html 7 | # 8 | # Contributors: 9 | # ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | ############################################################################### 11 | 12 | error_missing_reference= Invalid Reference - Unable to resolve the reference. \n\ 13 | The value must be a valid JSON Reference (for external references) or JSON Pointer (for local references), and must resolve to an object of the expected type. 14 | error_invalid_reference= Invalid Reference Syntax - The referenced path or URI may contain invalid characters. \n\ 15 | The value must be a valid JSON Reference (for external references) or JSON Pointer (for local references), and must resolve to an object of the expected type. 16 | warning_simple_reference = Simplified reference syntax is deprecated. The reference should be a valid JSON pointer. 17 | content_assist_proposal_local = Press '%s' to show %s in the current file. 18 | content_assist_proposal_project = Press '%s' to show all %s in the project. 19 | content_assist_proposal_workspace = Press '%s' to show all %s in the workspace. -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/messages.properties: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (c) 2016 ModelSolv, Inc. and others. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the Eclipse Public License v1.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.eclipse.org/legal/epl-v10.html 7 | # 8 | # Contributors: 9 | # ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | ############################################################################### 11 | 12 | outline_proposal_local = Press '%s' to show elements only the from current file 13 | outline_proposal_project = Press '%s' to show elements from the current project files 14 | outline_proposal_workspace = Press '%s' to show elements from the current workspace files 15 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/model/ArrayNode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.model; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | 18 | public class ArrayNode extends AbstractNode { 19 | 20 | private final List elements = new ArrayList<>(); 21 | 22 | ArrayNode(Model model, AbstractNode parent, JsonPointer ptr) { 23 | super(model, parent, ptr); 24 | } 25 | 26 | @Override 27 | public AbstractNode get(int pos) { 28 | return elements.get(pos); 29 | } 30 | 31 | @Override 32 | public ArrayNode asArray() { 33 | return this; 34 | } 35 | 36 | @Override 37 | public boolean isArray() { 38 | return true; 39 | } 40 | 41 | public void add(AbstractNode model) { 42 | this.elements.add(model); 43 | } 44 | 45 | @Override 46 | public AbstractNode[] elements() { 47 | return elements.toArray(new AbstractNode[elements.size()]); 48 | } 49 | 50 | @Override 51 | public String getText() { 52 | return getProperty() == null ? "" : getProperty(); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "[ " + elements + " ]"; 58 | } 59 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/model/Location.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.model; 12 | 13 | /** 14 | * Location inside a document represented by a line and a column. 15 | */ 16 | public class Location { 17 | 18 | private final int line; 19 | private final int column; 20 | 21 | public Location(int line, int column) { 22 | this.line = line; 23 | this.column = column; 24 | } 25 | 26 | public int getLine() { 27 | return line; 28 | } 29 | 30 | public int getColumn() { 31 | return column; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | StringBuilder builder = new StringBuilder(); 37 | builder.append("Location [line="); 38 | builder.append(line); 39 | builder.append(", column="); 40 | builder.append(column); 41 | builder.append("]"); 42 | return builder.toString(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/model/ObjectNode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.model; 12 | 13 | import java.util.Collection; 14 | import java.util.LinkedHashMap; 15 | import java.util.Map; 16 | 17 | import com.fasterxml.jackson.core.JsonPointer; 18 | 19 | public class ObjectNode extends AbstractNode { 20 | 21 | private final Map elements = new LinkedHashMap<>(); 22 | 23 | ObjectNode(Model model, AbstractNode parent, JsonPointer ptr) { 24 | super(model, parent, ptr); 25 | } 26 | 27 | @Override 28 | public AbstractNode get(int pos) { 29 | return elements()[pos]; 30 | } 31 | 32 | @Override 33 | public AbstractNode get(String property) { 34 | return elements.get(property); 35 | } 36 | 37 | public AbstractNode put(String property, AbstractNode value) { 38 | this.elements.put(property, value); 39 | return this; 40 | } 41 | 42 | public Collection fieldNames() { 43 | return elements.keySet(); 44 | } 45 | 46 | @Override 47 | public boolean isObject() { 48 | return true; 49 | } 50 | 51 | @Override 52 | public ObjectNode asObject() { 53 | return this; 54 | } 55 | 56 | @Override 57 | public AbstractNode[] elements() { 58 | return elements.values().toArray(new AbstractNode[elements.size()]); 59 | } 60 | 61 | @Override 62 | public String getText() { 63 | return getProperty() == null ? "" : getProperty(); 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return elements.toString(); 69 | } 70 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/model/ValueNode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.model; 12 | 13 | import com.fasterxml.jackson.core.JsonPointer; 14 | 15 | public class ValueNode extends AbstractNode { 16 | 17 | private final Object value; 18 | 19 | ValueNode(Model model, AbstractNode parent, JsonPointer ptr, Object value) { 20 | super(model, parent, ptr); 21 | 22 | this.value = value; 23 | } 24 | 25 | @Override 26 | public boolean isValue() { 27 | return true; 28 | } 29 | 30 | @Override 31 | public ValueNode asValue() { 32 | return this; 33 | } 34 | 35 | public Object getValue() { 36 | return value; 37 | } 38 | 39 | @Override 40 | public String getText() { 41 | String text = getProperty() != null ? getProperty() + ": " : ""; 42 | return text + (value != null ? getValue().toString() : ""); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return getText(); 48 | } 49 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/preferences/KaiZenPreferencesUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.preferences; 12 | 13 | import org.dadacoalition.yedit.preferences.PreferenceConstants; 14 | import org.eclipse.jface.preference.IPreferenceStore; 15 | 16 | public class KaiZenPreferencesUtils { 17 | public static int getTabWidth() { 18 | IPreferenceStore prefs = org.dadacoalition.yedit.Activator.getDefault().getPreferenceStore(); 19 | return prefs.getInt(PreferenceConstants.SPACES_PER_TAB); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/preferences/KaizenPreferencePage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.preferences; 12 | 13 | import org.eclipse.jface.preference.FieldEditorPreferencePage; 14 | import org.eclipse.ui.IWorkbench; 15 | import org.eclipse.ui.IWorkbenchPreferencePage; 16 | 17 | public class KaizenPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { 18 | 19 | public static final String VALIDATION_PREFERENCE_PAGE = "com.reprezen.swagedit.preferences.validation"; 20 | 21 | public KaizenPreferencePage() { 22 | super(GRID); 23 | setDescription("KaiZen OpenAPI Editor Preferences"); 24 | } 25 | 26 | @Override 27 | public void init(IWorkbench workbench) { 28 | // TODO Auto-generated method stub 29 | 30 | } 31 | 32 | @Override 33 | protected void createFieldEditors() { 34 | // TODO Auto-generated method stub 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/providers/PreferenceProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2019 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.providers; 12 | 13 | import java.util.List; 14 | 15 | import org.eclipse.jface.preference.FieldEditor; 16 | import org.eclipse.jface.preference.IPreferenceStore; 17 | import org.eclipse.swt.widgets.Composite; 18 | 19 | import com.reprezen.swagedit.core.editor.JsonDocument; 20 | 21 | /** 22 | * Client may implement this interface to provide custom preferences to KaiZen editors. 23 | * 24 | * Implementations should provide an extension to the extension point com.reprezen.swagedit.preferences. 25 | * 26 | */ 27 | public interface PreferenceProvider { 28 | 29 | public static final String ID = "com.reprezen.swagedit.preferences"; 30 | 31 | /** 32 | * Returns a list of editors that should be added to the preference page. 33 | * 34 | * @param version 35 | * of document 36 | * @param composite 37 | * @return 38 | */ 39 | List createFields(JsonDocument.Version version, Composite composite); 40 | 41 | /** 42 | * Initializes provided preferences into the given preference store. 43 | * 44 | * @param version 45 | * of document 46 | * @param store 47 | * to access preferences 48 | */ 49 | void initializeDefaultPreferences(JsonDocument.Version version, IPreferenceStore store); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/providers/ValidationProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2019 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.providers; 12 | 13 | import java.net.URI; 14 | import java.util.Set; 15 | 16 | import com.reprezen.swagedit.core.editor.JsonDocument; 17 | import com.reprezen.swagedit.core.model.AbstractNode; 18 | import com.reprezen.swagedit.core.validation.SwaggerError; 19 | 20 | /** 21 | * Client can implement this interface to provide custom validators. 22 | * 23 | * Implementations should be registered as extensions to the extension point com.reprezen.swagedit.validator. 24 | */ 25 | public interface ValidationProvider { 26 | 27 | public static final String ID = "com.reprezen.swagedit.validator"; 28 | 29 | /** 30 | * Execute a validation on the node present in the document. 31 | * 32 | * @param document 33 | * which contains the node. 34 | * @param baseURI 35 | * of the document. 36 | * @param node 37 | * to be validated. 38 | * @return validation errors. 39 | */ 40 | Set validate(JsonDocument document, URI baseURI, AbstractNode node); 41 | 42 | /** 43 | * Returns true if the validation should be performed. 44 | * 45 | * @param document 46 | * being validated. 47 | * @return true if validator is active. 48 | */ 49 | boolean isActive(JsonDocument document); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/schema/ArrayTypeDefinition.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.schema; 12 | 13 | import com.fasterxml.jackson.core.JsonPointer; 14 | import com.fasterxml.jackson.databind.JsonNode; 15 | 16 | /** 17 | * Represents a JSON schema type definition for arrays. 18 | * 19 | *
20 | * 21 | * Example of an array type definition: 22 | * 23 | * 24 | *
25 |  * "tags": {
26 |  *   "type": "array",
27 |  *   "items": {
28 |  *     "$ref": "#/definitions/tag"
29 |  *   },
30 |  *   "uniqueItems": true
31 |  * }
32 |  * 
33 | *
34 | * 35 | */ 36 | public class ArrayTypeDefinition extends TypeDefinition { 37 | 38 | public final TypeDefinition itemsType; 39 | 40 | public ArrayTypeDefinition(JsonSchema schema, JsonPointer pointer, JsonNode definition) { 41 | super(schema, pointer, definition, JsonType.ARRAY); 42 | itemsType = schema.createType(this, "items", definition.get("items")); 43 | } 44 | 45 | @Override 46 | public TypeDefinition getPropertyType(String property) { 47 | return itemsType; 48 | } 49 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/schema/JsonSchemaUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2017 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.schema; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.StringJoiner; 16 | 17 | import com.fasterxml.jackson.databind.JsonNode; 18 | import com.fasterxml.jackson.databind.node.ArrayNode; 19 | 20 | public class JsonSchemaUtils { 21 | public static String getHumanFriendlyText(JsonNode swaggerSchemaNode, final String defaultValue) { 22 | String schemaTitle = getSchemaTitle(swaggerSchemaNode); 23 | if (schemaTitle != null) { 24 | return schemaTitle; 25 | } 26 | // nested array 27 | if (swaggerSchemaNode.get("items") != null) { 28 | return getHumanFriendlyText(swaggerSchemaNode.get("items"), defaultValue); 29 | } 30 | // "$ref":"#/definitions/headerParameterSubSchema" 31 | JsonNode ref = swaggerSchemaNode.get("$ref"); 32 | if (ref != null) { 33 | return getLabelForRef(ref.asText()); 34 | } 35 | // Auxiliary oneOf in "oneOf": [ { "$ref": "#/definitions/securityRequirement" }] 36 | JsonNode oneOf = swaggerSchemaNode.get("oneOf"); 37 | if (oneOf != null) { 38 | if (oneOf instanceof ArrayNode) { 39 | ArrayNode arrayNode = (ArrayNode) oneOf; 40 | if (arrayNode.size() > 0) { 41 | List labels = new ArrayList<>(); 42 | arrayNode.elements().forEachRemaining(el -> labels.add(getHumanFriendlyText(el, defaultValue))); 43 | StringJoiner joiner = new StringJoiner(", ", "[", "]"); 44 | labels.forEach(joiner::add); 45 | return joiner.toString(); 46 | } 47 | } 48 | } 49 | return defaultValue; 50 | } 51 | 52 | public static String getSchemaTitle(JsonNode swaggerSchemaNode) { 53 | JsonNode title = swaggerSchemaNode.get("title"); 54 | if (title != null) { 55 | return title.asText(); 56 | } 57 | return null; 58 | } 59 | 60 | public static String getLabelForRef(String refValue) { 61 | return refValue.substring(refValue.lastIndexOf("/") + 1); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/schema/JsonType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.schema; 12 | 13 | import com.fasterxml.jackson.databind.JsonNode; 14 | 15 | /** 16 | * Enumeration of JSON types found in a JSON schema. 17 | */ 18 | public enum JsonType { 19 | OBJECT("object"), // 20 | ARRAY("array"), // 21 | STRING("string"), // 22 | NUMBER("number"), // 23 | INTEGER("integer"), // 24 | BOOLEAN("boolean"), // 25 | ONE_OF("oneOf"), // 26 | ENUM("enum"), // 27 | ANY_OF("anyOf"), // 28 | ALL_OF("allOf"), // 29 | UNDEFINED("undefined"); 30 | 31 | private final String value; 32 | 33 | private JsonType(String value) { 34 | this.value = value; 35 | } 36 | 37 | public String getValue() { 38 | return value; 39 | } 40 | 41 | public static JsonType valueOf(JsonNode node) { 42 | if (node == null) { 43 | return JsonType.UNDEFINED; 44 | } else if (node.has("oneOf")) { 45 | return JsonType.ONE_OF; 46 | } else if (node.has("enum")) { 47 | return JsonType.ENUM; 48 | } else if (node.has("type")) { 49 | String type = node.has("type") ? node.get("type").asText() : null; 50 | 51 | if (type != null) { 52 | for (JsonType jsonType : JsonType.values()) { 53 | if (type.equals(jsonType.getValue())) { 54 | return jsonType; 55 | } 56 | } 57 | } 58 | } else if (node.has("properties")) { 59 | return JsonType.OBJECT; 60 | } else if (node.has("anyOf")) { 61 | return JsonType.ANY_OF; 62 | } else if (node.has("allOf")) { 63 | return JsonType.ALL_OF; 64 | } 65 | 66 | return JsonType.UNDEFINED; 67 | } 68 | 69 | public boolean isValueType() { 70 | return this == INTEGER || this == JsonType.STRING || this == JsonType.BOOLEAN || this == JsonType.NUMBER; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/schema/MultipleTypeDefinition.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.schema; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Represents a JSON schema type definition that is defined in separated types. 17 | * 18 | */ 19 | public class MultipleTypeDefinition extends TypeDefinition { 20 | 21 | private final List multipleTypes; 22 | 23 | public MultipleTypeDefinition(JsonSchema schema, List multipleTypes) { 24 | super(schema, null, null, JsonType.UNDEFINED); 25 | this.multipleTypes = multipleTypes; 26 | } 27 | 28 | public List getMultipleTypes() { 29 | return multipleTypes; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return multipleTypes.toString(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/schema/ReferenceTypeDefinition.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.schema; 12 | 13 | import com.fasterxml.jackson.core.JsonPointer; 14 | import com.fasterxml.jackson.databind.JsonNode; 15 | import com.reprezen.swagedit.core.json.references.JsonReference; 16 | 17 | /** 18 | * Represents a JSON reference that should be resolved as a type definition. 19 | * 20 | */ 21 | public class ReferenceTypeDefinition extends TypeDefinition { 22 | 23 | private TypeDefinition resolved; 24 | 25 | public ReferenceTypeDefinition(JsonSchema schema, JsonPointer pointer, JsonNode definition) { 26 | super(schema, pointer, definition, JsonType.UNDEFINED); 27 | } 28 | 29 | public TypeDefinition resolve() { 30 | if (resolved != null) { 31 | return resolved; 32 | } 33 | return resolved = schema.getManager().resolve(this, content.get(JsonReference.PROPERTY).asText()); 34 | } 35 | 36 | @Override 37 | public JsonType getType() { 38 | return resolve().getType(); 39 | } 40 | 41 | @Override 42 | public String getDescription() { 43 | return resolve().getDescription(); 44 | } 45 | 46 | @Override 47 | public JsonPointer getPointer() { 48 | return resolve().getPointer(); 49 | } 50 | 51 | @Override 52 | public JsonNode asJson() { 53 | return resolve().asJson(); 54 | } 55 | 56 | @Override 57 | public String getContainingProperty() { 58 | return resolve().getContainingProperty(); 59 | } 60 | 61 | @Override 62 | public TypeDefinition getPropertyType(String property) { 63 | return resolve().getPropertyType(property); 64 | } 65 | 66 | @Override 67 | public String getLabel() { 68 | String label = JsonSchemaUtils.getSchemaTitle(content); 69 | if (label != null) { 70 | return label; 71 | } 72 | // $ref=schemaOrReference 73 | if (resolve() instanceof ComplexTypeDefinition) { 74 | return resolve().getLabel(); 75 | } 76 | // $ref=schema 77 | return JsonSchemaUtils.getLabelForRef(content.get(JsonReference.PROPERTY).asText()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/templates/ElementNameResolver.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.templates; 12 | 13 | import java.util.List; 14 | 15 | import org.eclipse.jface.text.templates.TemplateContext; 16 | import org.eclipse.jface.text.templates.TemplateVariable; 17 | import org.eclipse.jface.text.templates.TemplateVariableResolver; 18 | 19 | /** 20 | * Standard code template variables can only define values that are valid variables, e.g. no space allowed.
21 | * This template variable resolver provides a way to create and select names with special characters (whitespaces, '(', ')') in code templates. For 22 | * example, `${element_name:element_name('(schema name)')}` creates `(schema name)` and selects it for editing. 23 | * 24 | */ 25 | public class ElementNameResolver extends TemplateVariableResolver { 26 | public ElementNameResolver() { 27 | super("element_name", "Provides human-friendly element name and selects it"); 28 | } 29 | 30 | @Override 31 | public void resolve(TemplateVariable variable, TemplateContext context) { 32 | List params = variable.getVariableType().getParams(); 33 | String[] bindings = new String[params.size()]; 34 | for (int i = 0; i < params.size(); i++) { 35 | bindings[i] = params.get(i).toString(); 36 | } 37 | if (bindings.length != 0) 38 | variable.setValues(bindings); 39 | variable.setResolved(true); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.reprezen.swagedit.core.utils; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | public class StringUtils { 8 | 9 | public static enum QuoteStyle { 10 | SINGLE("'"), // 11 | DOUBLE("\""), // 12 | INVALID(null); 13 | 14 | private final String value; 15 | 16 | QuoteStyle(String value) { 17 | this.value = value; 18 | } 19 | 20 | public String getValue() { 21 | return value; 22 | } 23 | 24 | public boolean isValid() { 25 | return this != INVALID; 26 | } 27 | 28 | public static QuoteStyle parse(char c) { 29 | if (c == '"') { 30 | return DOUBLE; 31 | } else if (c == '\'') { 32 | return SINGLE; 33 | } else { 34 | return INVALID; 35 | } 36 | } 37 | } 38 | 39 | public static boolean isQuoted(String string) { 40 | return emptyToNull(string) != null && (string.charAt(0) == '"' || string.charAt(0) == '\''); 41 | } 42 | 43 | public static QuoteStyle tryGetQuotes(String string) { 44 | return isQuoted(string) ? QuoteStyle.parse(string.charAt(0)): QuoteStyle.INVALID; 45 | } 46 | 47 | public static boolean isNullOrEmpty(String string) { 48 | return string == null || string.trim().isEmpty(); 49 | } 50 | 51 | public static String emptyToNull(String string) { 52 | return (string == null || string.isEmpty()) ? null : string; 53 | } 54 | 55 | public static String nullToEmpty(String string) { 56 | return string == null ? "" : string; 57 | } 58 | 59 | public static String toString(InputStream contents) throws IOException { 60 | ByteArrayOutputStream result = new ByteArrayOutputStream(); 61 | byte[] buffer = new byte[1024]; 62 | int length; 63 | while ((length = contents.read(buffer)) != -1) { 64 | result.write(buffer, 0, length); 65 | } 66 | return result.toString("UTF-8"); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/utils/URLUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.utils; 12 | 13 | import java.io.UnsupportedEncodingException; 14 | import java.net.URLEncoder; 15 | 16 | public class URLUtils { 17 | 18 | /* 19 | * Encodes that path string so that it does not include illegal characters in respect to URL encoding. (see 20 | * http://stackoverflow 21 | * .com/questions/607176/java-equivalent-to-javascripts-encodeuricomponent-that-produces-identical-outpu) 22 | */ 23 | public static String encodeURL(String path) { 24 | try { 25 | return URLEncoder.encode(path, "UTF-8") 26 | // decode characters that don't 27 | // need to be encoded. 28 | .replaceAll("\\+", "%20") // 29 | .replaceAll("\\%21", "!") // 30 | .replaceAll("\\%2F", "/") // 31 | .replaceAll("\\%23", "#") // 32 | .replaceAll("\\%27", "'") // 33 | .replaceAll("\\%7E", "~"); 34 | } catch (UnsupportedEncodingException e) { 35 | return path; 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/validation/Markers.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2013, 2019 Modelsolv, Inc. 3 | * All Rights Reserved. 4 | * 5 | * NOTICE: All information contained herein is, and remains the property 6 | * of ModelSolv, Inc. See the file license.html in the root directory of 7 | * this project for further information. 8 | *******************************************************************************/ 9 | package com.reprezen.swagedit.core.validation; 10 | 11 | import org.dadacoalition.yedit.YEditLog; 12 | import org.eclipse.core.resources.IFile; 13 | import org.eclipse.core.resources.IMarker; 14 | import org.eclipse.core.runtime.CoreException; 15 | import org.eclipse.ui.texteditor.IDocumentProvider; 16 | 17 | import com.reprezen.swagedit.core.editor.JsonDocument; 18 | import com.reprezen.swagedit.core.editor.JsonEditor; 19 | 20 | public class Markers { 21 | 22 | public static final String DOCUMENT_VERSION_MARKER = "kaizen.version.marker"; 23 | 24 | public static void addMarker(JsonEditor editor, IFile target, SwaggerError error) { 25 | try { 26 | IDocumentProvider provider = editor.getDocumentProvider(); 27 | JsonDocument document = (JsonDocument) provider.getDocument(editor.getEditorInput()); 28 | 29 | IMarker marker = target.createMarker(IMarker.PROBLEM); 30 | marker.setAttribute(IMarker.SEVERITY, error.getLevel()); 31 | marker.setAttribute(IMarker.MESSAGE, error.getMessage()); 32 | marker.setAttribute(IMarker.LINE_NUMBER, error.getLine()); 33 | 34 | if (!error.getMarkerAttributes().isEmpty()) { 35 | marker.setAttribute(DOCUMENT_VERSION_MARKER, document.getVersion().name()); 36 | 37 | error.getMarkerAttributes().forEach((key, value) -> { 38 | try { 39 | marker.setAttribute(key, value); 40 | } catch (CoreException e) { 41 | YEditLog.logException(e); 42 | } 43 | }); 44 | } 45 | } catch (CoreException e) { 46 | YEditLog.logException(e); 47 | YEditLog.logger.warning("Failed to create marker for syntax error: \n" + e.toString()); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/wizard/NewFileWizard.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.core.wizard; 12 | 13 | import org.eclipse.core.resources.IFile; 14 | import org.eclipse.jface.viewers.IStructuredSelection; 15 | import org.eclipse.jface.wizard.Wizard; 16 | import org.eclipse.ui.INewWizard; 17 | import org.eclipse.ui.IWorkbench; 18 | import org.eclipse.ui.IWorkbenchPage; 19 | import org.eclipse.ui.IWorkbenchWizard; 20 | import org.eclipse.ui.PartInitException; 21 | import org.eclipse.ui.PlatformUI; 22 | import org.eclipse.ui.dialogs.WizardNewFileCreationPage; 23 | import org.eclipse.ui.ide.IDE; 24 | 25 | public abstract class NewFileWizard extends Wizard implements INewWizard { 26 | 27 | private WizardNewFileCreationPage page; 28 | private IStructuredSelection selection; 29 | private String editorId; 30 | 31 | abstract protected WizardNewFileCreationPage newFileCreationPage(IStructuredSelection selection); 32 | 33 | public NewFileWizard(String editorId) { 34 | super(); 35 | this.editorId = editorId; 36 | setNeedsProgressMonitor(true); 37 | } 38 | 39 | /** 40 | * Adding the page to the wizard. 41 | */ 42 | public void addPages() { 43 | page = newFileCreationPage(selection); 44 | addPage(page); 45 | } 46 | 47 | @Override 48 | public boolean performFinish() { 49 | final IFile file = page.createNewFile(); 50 | if (file == null || !file.exists()) { 51 | return false; 52 | } 53 | 54 | getShell().getDisplay().asyncExec(new Runnable() { 55 | public void run() { 56 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 57 | try { 58 | IDE.openEditor(page, file, editorId); 59 | } catch (PartInitException e) { 60 | } 61 | } 62 | }); 63 | 64 | return true; 65 | } 66 | 67 | /** 68 | * We will accept the selection in the workbench to see if we can initialize from it. 69 | * 70 | * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection) 71 | */ 72 | public void init(IWorkbench workbench, IStructuredSelection selection) { 73 | this.selection = selection; 74 | } 75 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.dependencies/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = META-INF/,\ 2 | lib/ 3 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.reprezen.swagedit.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.FeatureBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.xtext.ui.shared.xtextNature 26 | org.eclipse.m2e.core.maven2Nature 27 | org.eclipse.pde.FeatureNature 28 | 29 | 30 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.feature/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.feature/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml -------------------------------------------------------------------------------- /com.reprezen.swagedit.feature/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | com.reprezen 7 | SwagEdit 8 | 0.8.0-SNAPSHOT 9 | ../pom.xml 10 | 11 | 12 | com.reprezen.swagedit.feature 13 | eclipse-feature 14 | 15 | 16 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.reprezen.swagedit.openapi3.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.m2e.core.maven2Nature 36 | org.eclipse.pde.PluginNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.xtext.ui.shared.xtextNature 39 | 40 | 41 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: KaiZen Editor Tests 4 | Bundle-SymbolicName: com.reprezen.swagedit.openapi3.tests 5 | Bundle-Version: 0.8.0.qualifier 6 | Fragment-Host: com.reprezen.swagedit.openapi3;bundle-version="0.8.0" 7 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 8 | Require-Bundle: org.junit;bundle-version="4.0.0", 9 | org.eclipse.xtend.lib, 10 | org.mockito;bundle-version="1.9.5", 11 | org.hamcrest;bundle-version="1.1.0" 12 | Bundle-ClassPath: . 13 | Bundle-Vendor: ModelSolv, Inc. d.b.a. RepreZen 14 | Automatic-Module-Name: com.reprezen.swagedit.openapi3.tests 15 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = .,\ 2 | META-INF/ 3 | jars.compile.order = . 4 | source.. = src/,\ 5 | xtend-gen/ 6 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | com.reprezen 7 | SwagEdit 8 | 0.8.0-SNAPSHOT 9 | ../pom.xml 10 | 11 | 12 | com.reprezen.swagedit.openapi3.tests 13 | eclipse-test-plugin 14 | 15 | 16 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/code-templates/HeadersObject.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Headers Object 4 | version: "1.0.0" 5 | servers: 6 | - url: https://api.uber.com/v1 7 | 8 | paths: 9 | 10 | /pets: 11 | get: 12 | summary: Read 13 | description: Provide details for the entire list (for collection resources) or an item (for object resources) 14 | responses: 15 | '200': 16 | description: A simple string response 17 | content: 18 | text/plain: 19 | schema: 20 | type: string 21 | example: 'whoa!' 22 | headers: 23 | X-Rate-Limit-Limit: 24 | description: The number of allowed requests in the current period 25 | schema: 26 | type: integer 27 | X-Rate-Limit-Remaining: 28 | description: The number of remaining requests in the current period 29 | schema: 30 | type: integer 31 | X-Rate-Limit-Reset: 32 | #KZOE-template name="header in response", value="header" 33 | $ref: "#/components/headers/X-Rate-Limit-Reset" 34 | 35 | components: 36 | headers: 37 | #KZOE-template name="headers in components/headers", value="headers" 38 | refed: 39 | #KZOE-template name="header in components/headers", value="header" 40 | $ref: "#/components/headers/X-Rate-Limit-Reset" 41 | 42 | X-Rate-Limit-Reset: 43 | description: The number of seconds left in the current period 44 | schema: 45 | type: integer 46 | 47 | requestBodies: 48 | requestBody: 49 | content: 50 | multipart/mixed: 51 | schema: 52 | type: string 53 | encoding: 54 | historyMetadata: 55 | # require XML Content-Type in utf-8 encoding 56 | contentType: application/xml; charset=utf-8 57 | profileImage: 58 | # only accept png/jpeg 59 | contentType: image/png, image/jpeg 60 | headers: 61 | X-Rate-Limit-Limit: 62 | #KZOE-template name="header in encoding", value="header" 63 | $ref: "#/components/headers/X-Rate-Limit-Reset" 64 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/code-templates/ParameterObject.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Headers Object 4 | version: "1.0.0" 5 | servers: 6 | - url: https://api.uber.com/v1 7 | 8 | paths: 9 | 10 | /pets: 11 | parameters: 12 | #KZOE-template name="parameter in path item", value="parameter" kzoe-arrayItem 13 | - $ref: "#/components/parameters/username" 14 | get: 15 | parameters: 16 | #KZOE-template name="parameter in operation", value="parameter" kzoe-arrayItem 17 | - $ref: "#/components/parameters/id" 18 | summary: Read 19 | description: Provide details for the entire list (for collection resources) or an item (for object resources) 20 | responses: 21 | '200': 22 | description: A simple string response 23 | 24 | components: 25 | 26 | parameters: 27 | #KZOE-template name="parameters in components/parameters", value="parameters" 28 | test: 29 | #KZOE-template name="parameter in components/parameters", value="parameter" 30 | $ref: "#/components/parameters/id" 31 | # header parameter 32 | token: 33 | name: token 34 | in: header 35 | description: token to be passed as a header 36 | required: true 37 | schema: 38 | type: array 39 | items: 40 | type: integer 41 | format: int64 42 | style: simple 43 | 44 | # path parameter 45 | username: 46 | name: username 47 | in: path 48 | description: username to fetch 49 | required: true 50 | schema: 51 | type: string 52 | 53 | # query parameter 54 | id: 55 | name: id 56 | in: query 57 | description: ID of the object to fetch 58 | required: false 59 | schema: 60 | type: array 61 | items: 62 | type: string 63 | style: form 64 | explode: true 65 | 66 | # freeform query parameter 67 | freeform: 68 | in: query 69 | name: freeForm 70 | schema: 71 | type: object 72 | additionalProperties: 73 | type: integer 74 | style: form -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/code-templates/ResponseObject.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Response Object 4 | version: "1.0.0" 5 | 6 | paths: 7 | 8 | /pets: 9 | get: 10 | summary: Read 11 | description: Provide 12 | responses: 13 | '200': 14 | #KZOE-template name="response operation 200", value="response" 15 | 16 | description: desc 17 | default: 18 | #KZOE-template name="response in operation default", value="response" 19 | 20 | description: desc 21 | 22 | components: 23 | #KZOE-template name="components in components", value="components" 24 | responses: 25 | #KZOE-template name="responses in components/responses", value="responses" 26 | clientErrorResponse: 27 | description: Client error 28 | circular: 29 | #KZOE-template name="response in components/responses", value="response" 30 | 31 | description: desc 32 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/code-templates/SecuitySchemesObject.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Security Schemes Object 4 | version: "1.0.0" 5 | 6 | paths: 7 | 8 | /pets: 9 | get: 10 | summary: Read 11 | description: Provide details for the entire list (for collection resources) or an item (for object resources) 12 | responses: 13 | 201: 14 | description: Null response 15 | security: 16 | - petstore_auth: 17 | - write:pets 18 | - read:pets 19 | 20 | components: 21 | 22 | securitySchemes: 23 | #KZOE-template name="securitySchemes in components/securitySchemes", value="securitySchemes" 24 | api_key: 25 | #KZOE-template name="security scheme object in components", value="securityScheme" 26 | type: apiKey 27 | name: api_key 28 | in: header 29 | petstore_auth: 30 | type: oauth2 31 | flows: 32 | implicit: 33 | authorizationUrl: http://example.org/api/oauth/dialog 34 | scopes: 35 | write:pets: modify pets in your account 36 | read:pets: read your pets 37 | 38 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/references/CallbacksObject.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Callbacks Object 4 | version: "1.0.0" 5 | 6 | paths: 7 | 8 | /pets: 9 | get: 10 | summary: Read 11 | description: Provide details for the entire list (for collection resources) or an item (for object resources) 12 | responses: 13 | 201: 14 | description: Null response 15 | callbacks: 16 | myWebhook: 17 | #KZOE-ref name="callback in operation", value="components/callbacks" 18 | $ref: "#/components/callbacks/myWebhook" 19 | 20 | components: 21 | 22 | callbacks: 23 | MyWebhooWithRef: 24 | #KZOE-ref name="callback in components/callback", value="components/callbacks" 25 | $ref: "#/components/callbacks/myWebhook" 26 | myWebhook: 27 | '$request.body#/url': 28 | post: 29 | requestBody: 30 | description: Callback payload 31 | content: 32 | 'application/json': 33 | schema: 34 | $ref: '#/components/schemas/SomePayload' 35 | responses: 36 | '200': 37 | description: webhook successfully processed and no retries will be performed 38 | 39 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/references/HeadersObject.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Headers Object 4 | version: "1.0.0" 5 | servers: 6 | - url: https://api.uber.com/v1 7 | 8 | paths: 9 | 10 | /pets: 11 | get: 12 | summary: Read 13 | description: Provide details for the entire list (for collection resources) or an item (for object resources) 14 | responses: 15 | '200': 16 | description: A simple string response 17 | content: 18 | text/plain: 19 | schema: 20 | type: string 21 | example: 'whoa!' 22 | headers: 23 | X-Rate-Limit-Limit: 24 | description: The number of allowed requests in the current period 25 | schema: 26 | type: integer 27 | X-Rate-Limit-Remaining: 28 | description: The number of remaining requests in the current period 29 | schema: 30 | type: integer 31 | X-Rate-Limit-Reset: 32 | #KZOE-ref name="header in response", value="components/headers" 33 | $ref: "#/components/headers/X-Rate-Limit-Reset" 34 | 35 | components: 36 | headers: 37 | 38 | refed: 39 | #KZOE-ref name="header in components/headers", value="components/headers" 40 | $ref: "#/components/headers/X-Rate-Limit-Reset" 41 | 42 | X-Rate-Limit-Reset: 43 | description: The number of seconds left in the current period 44 | schema: 45 | type: integer 46 | 47 | requestBodies: 48 | requestBody: 49 | content: 50 | multipart/mixed: 51 | schema: 52 | type: string 53 | encoding: 54 | historyMetadata: 55 | # require XML Content-Type in utf-8 encoding 56 | contentType: application/xml; charset=utf-8 57 | profileImage: 58 | # only accept png/jpeg 59 | contentType: image/png, image/jpeg 60 | headers: 61 | X-Rate-Limit-Limit: 62 | #KZOE-ref name="header in encoding", value="components/headers" 63 | $ref: "#/components/headers/X-Rate-Limit-Reset" 64 | 65 | 66 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/references/Parameter.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Headers Object 4 | version: "1.0.0" 5 | servers: 6 | - url: https://api.uber.com/v1 7 | 8 | paths: 9 | 10 | /pets: 11 | parameters: 12 | #KZOE-ref name="parameter in path item", value="components/parameters" kzoe-arrayItem 13 | - $ref: "#/components/parameters/username" 14 | get: 15 | parameters: 16 | #KZOE-ref name="parameter in operation", value="components/parameters" kzoe-arrayItem 17 | - $ref: "#/components/parameters/id" 18 | summary: Read 19 | description: Provide details for the entire list (for collection resources) or an item (for object resources) 20 | responses: 21 | '200': 22 | description: A simple string response 23 | 24 | components: 25 | 26 | parameters: 27 | test: 28 | #KZOE-ref name="parameter in components/parameters", value="components/parameters" 29 | $ref: "#/components/parameters/id" 30 | # header parameter 31 | token: 32 | name: token 33 | in: header 34 | description: token to be passed as a header 35 | required: true 36 | schema: 37 | type: array 38 | items: 39 | type: integer 40 | format: int64 41 | style: simple 42 | 43 | # path parameter 44 | username: 45 | name: username 46 | in: path 47 | description: username to fetch 48 | required: true 49 | schema: 50 | type: string 51 | 52 | # query parameter 53 | id: 54 | name: id 55 | in: query 56 | description: ID of the object to fetch 57 | required: false 58 | schema: 59 | type: array 60 | items: 61 | type: string 62 | style: form 63 | explode: true 64 | 65 | # freeform query parameter 66 | freeform: 67 | in: query 68 | name: freeForm 69 | schema: 70 | type: object 71 | additionalProperties: 72 | type: integer 73 | style: form -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/references/PathItem.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Callbacks Object 4 | version: "1.0.0" 5 | 6 | paths: 7 | 8 | /pets: 9 | #KZOE-ref name="path item in paths", value="paths" 10 | $ref: "HeadersObject.yaml#/paths/~1pets" 11 | 12 | components: 13 | 14 | callbacks: 15 | myWebhook: 16 | '$request.body#/url': 17 | #KZOE-ref name="path item in callback", value="paths" 18 | $ref: "HeadersObject.yaml#/paths/~1pets" 19 | 20 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/references/ResponseObject.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Response Object 4 | version: "1.0.0" 5 | 6 | paths: 7 | 8 | /pets: 9 | get: 10 | summary: Read 11 | description: Provide 12 | responses: 13 | '200': 14 | #KZOE-ref name="response operation 200", value="components/responses" 15 | $ref: "#/components/responses/clientErrorResponse" 16 | default: 17 | #KZOE-ref name="response in operation default", value="components/responses" 18 | $ref: "#/components/responses/clientErrorResponse" 19 | 20 | components: 21 | responses: 22 | clientErrorResponse: 23 | description: Client error 24 | circular: 25 | #KZOE-ref name="response in components/responses", value="components/responses" 26 | $ref: "#/components/responses/clientErrorResponse" 27 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/code-assist/references/SecuitySchemesObject.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Security Schemes Object 4 | version: "1.0.0" 5 | 6 | paths: 7 | 8 | /pets: 9 | get: 10 | summary: Read 11 | description: Provide details for the entire list (for collection resources) or an item (for object resources) 12 | responses: 13 | 201: 14 | description: Null response 15 | security: 16 | - petstore_auth: 17 | - write:pets 18 | - read:pets 19 | 20 | components: 21 | 22 | securitySchemes: 23 | api_key: 24 | type: apiKey 25 | name: api_key 26 | in: header 27 | petstore_auth: 28 | type: oauth2 29 | flows: 30 | implicit: 31 | authorizationUrl: http://example.org/api/oauth/dialog 32 | scopes: 33 | write:pets: modify pets in your account 34 | read:pets: read your pets 35 | 36 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/spec_examples/v3.0/callback-example.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | info: 3 | title: Callback Example 4 | version: 1.0.0 5 | paths: 6 | /streams: 7 | post: 8 | description: subscribes a client to receive out-of-band data 9 | parameters: 10 | - name: callbackUrl 11 | in: query 12 | required: true 13 | description: | 14 | the location where data will be sent. Must be network accessible 15 | by the source server 16 | schema: 17 | type: string 18 | format: uri 19 | example: https://tonys-server.com 20 | responses: 21 | '201': 22 | description: subscription successfully created 23 | content: 24 | application/json: 25 | schema: 26 | description: subscription information 27 | required: 28 | - subscriptionId 29 | properties: 30 | subscriptionId: 31 | description: this unique identifier allows management of the subscription 32 | type: string 33 | example: 2531329f-fb09-4ef7-887e-84e648214436 34 | callbacks: 35 | # the name `onData` is a convenience locator 36 | onData: 37 | # when data is sent, it will be sent to the `callbackUrl` provided 38 | # when making the subscription PLUS the suffix `/data` 39 | '{$request.query.callbackUrl}/data': 40 | post: 41 | requestBody: 42 | description: subscription payload 43 | content: 44 | application/json: 45 | schema: 46 | properties: 47 | timestamp: 48 | type: string 49 | format: date-time 50 | userData: 51 | type: string 52 | responses: 53 | '202': 54 | description: | 55 | Your server implementation should return this HTTP status code 56 | if the data was received successfully 57 | '204': 58 | description: | 59 | Your server should return this HTTP status code if no longer interested 60 | in further updates -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/resources/tests/validation_type.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | info: 3 | version: "1.0" 4 | title: Foo 5 | 6 | paths: 7 | /foo: 8 | get: 9 | responses: 10 | 200: 11 | description: "OK" 12 | content: 13 | default: 14 | schema: 15 | type: xxx -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/src/com/reprezen/swagedit/openapi3/assist/CodeTemplateContextTest.xtend: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.assist 12 | 13 | import java.io.File 14 | import java.nio.file.Paths 15 | import java.util.Collection 16 | import org.junit.Test 17 | import org.junit.runner.RunWith 18 | import org.junit.runners.Parameterized 19 | import org.junit.runners.Parameterized.Parameter 20 | import org.junit.runners.Parameterized.Parameters 21 | 22 | import static com.reprezen.swagedit.openapi3.assist.CodeAssistHelper.* 23 | import static org.junit.Assert.* 24 | 25 | @RunWith(typeof(Parameterized)) 26 | class CodeTemplateContextTest { 27 | 28 | val static KZOEref = "#KZOE-template" 29 | 30 | @Parameter 31 | var public File specFile 32 | 33 | @Parameter(1) 34 | var public String fileName // for test name only 35 | 36 | @Parameter(2) 37 | var public int offset // for test name only 38 | 39 | @Parameter(3) 40 | var public String testName // for test name only 41 | 42 | 43 | @Parameters(name="{index}: {1} - {3}") 44 | def static Collection data() { 45 | val resourcesDir = Paths.get("resources", "code-assist", "code-templates").toFile(); 46 | return new CodeAssistHelper().extractTests(resourcesDir, KZOEref).map[#[it.file, it.file.name, it.offset, it.name] as Object[]] 47 | } 48 | 49 | @Test 50 | def void test_code_template_context() { 51 | val document = createOpenApi3Document(specFile) 52 | 53 | val region = document.getLineInformationOfOffset(offset) 54 | 55 | val contextType = getCodeTemplateContext(document, offset) 56 | 57 | val annotationLine = document.get(region.offset, region.getLength()) 58 | val matcher = refValuePattern.matcher(annotationLine) 59 | if (matcher.matches) { 60 | val String refValue = matcher.group(1); 61 | assertNotNull("Code-template context is null, but expected: " + refValue, contextType) 62 | assertEquals(refValue, contextType.name); 63 | } else { 64 | fail("Invalid test annotation line: " + annotationLine) 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/src/com/reprezen/swagedit/openapi3/editor/OpenApi3ContentTypeTest.xtend: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.editor 12 | 13 | import static org.junit.Assert.* 14 | import org.junit.Test 15 | 16 | class OpenApi3ContentTypeTest { 17 | 18 | @Test 19 | def void double_quotes() { 20 | val String content = ''' 21 | openapi: "3.0.0" 22 | info:'''; 23 | assertTrue(new OpenApi3ContentDescriber().isSupported(content)); 24 | } 25 | 26 | @Test 27 | def void single_quotes() { 28 | val String content = ''' 29 | openapi: '3.0.0' 30 | info:'''; 31 | assertTrue(new OpenApi3ContentDescriber().isSupported(content)); 32 | } 33 | 34 | @Test 35 | def void no_quotes() { 36 | val String content = ''' 37 | openapi: 3.0.0 38 | info:'''; 39 | assertTrue(new OpenApi3ContentDescriber().isSupported(content)); 40 | } 41 | @Test 42 | def void spec_with_comment() { 43 | val String content = ''' 44 | #a comment 45 | openapi: "3.0.0" 46 | info:'''; 47 | assertTrue(new OpenApi3ContentDescriber().isSupported(content)); 48 | } 49 | 50 | @Test 51 | def void version_with_release_candidate() { 52 | val String content = ''' 53 | openapi: '3.0.0-RC0' 54 | info:'''; 55 | assertTrue(new OpenApi3ContentDescriber().isSupported(content)); 56 | } 57 | 58 | @Test 59 | def void no_closing_quotes_not_supported() { 60 | val String content = ''' 61 | openapi: '3.0.0 62 | info:'''; 63 | assertFalse(new OpenApi3ContentDescriber().isSupported(content)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3.tests/src/com/reprezen/swagedit/openapi3/validation/KaizenValidationTest.xtend: -------------------------------------------------------------------------------- 1 | package com.reprezen.swagedit.openapi3.validation 2 | 3 | import com.reprezen.swagedit.openapi3.editor.OpenApi3Document 4 | import com.reprezen.swagedit.openapi3.schema.OpenApi3Schema 5 | import java.nio.file.Files 6 | import java.nio.file.Paths 7 | import org.junit.Test 8 | 9 | import static org.junit.Assert.* 10 | 11 | class KaizenValidationTest { 12 | 13 | val validator = ValidationHelper.validator(true) 14 | val document = new OpenApi3Document(new OpenApi3Schema) 15 | 16 | @Test 17 | def void testValidation_OnMInvalidType() { 18 | val resource = Paths.get("resources", "tests", "validation_type.yaml") 19 | 20 | document.set(new String(Files.readAllBytes(resource))) 21 | 22 | val errors = validator.validate(document, resource.toUri) 23 | assertEquals(1, errors.size()) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.reprezen.swagedit.openapi3 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.xtext.ui.shared.xtextNature 36 | org.eclipse.m2e.core.maven2Nature 37 | org.eclipse.pde.PluginNature 38 | org.eclipse.jdt.core.javanature 39 | 40 | 41 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: KaiZen OpenAPI Editor for OpenAPI v3 4 | Bundle-SymbolicName: com.reprezen.swagedit.openapi3;singleton:=true 5 | Bundle-Version: 0.8.0.qualifier 6 | Bundle-Activator: com.reprezen.swagedit.openapi3.Activator 7 | Bundle-Vendor: ModelSolv, Inc. d.b.a. RepreZen 8 | Require-Bundle: org.eclipse.ui, 9 | org.eclipse.core.runtime, 10 | org.eclipse.ui.editors, 11 | org.eclipse.jface.text, 12 | org.dadacoalition.yedit, 13 | com.reprezen.swagedit.core, 14 | org.eclipse.ui.ide, 15 | org.eclipse.core.resources, 16 | com.github.eclipsecolortheme;resolution:=optional, 17 | com.reprezen.swagedit.dependencies;bundle-version="0.8.0" 18 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 19 | Bundle-ActivationPolicy: lazy 20 | Export-Package: com.reprezen.swagedit.openapi3, 21 | com.reprezen.swagedit.openapi3.assist, 22 | com.reprezen.swagedit.openapi3.assist.contexts, 23 | com.reprezen.swagedit.openapi3.assist.ext, 24 | com.reprezen.swagedit.openapi3.editor, 25 | com.reprezen.swagedit.openapi3.editor.wizard, 26 | com.reprezen.swagedit.openapi3.hyperlinks, 27 | com.reprezen.swagedit.openapi3.preferences, 28 | com.reprezen.swagedit.openapi3.schema, 29 | com.reprezen.swagedit.openapi3.templates, 30 | com.reprezen.swagedit.openapi3.validation 31 | Bundle-ClassPath: . 32 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/OSGI-INF/l10n/bundle.properties: -------------------------------------------------------------------------------- 1 | content-type.name = OpenAPI v3 Content Type 2 | editor.name = OpenAPI v3 Editor -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = target/classes/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | OSGI-INF/,\ 6 | plugin.xml,\ 7 | icons/,\ 8 | resources/ 9 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/icons/OpenAPI_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit.openapi3/icons/OpenAPI_16.png -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/icons/OpenAPI_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit.openapi3/icons/OpenAPI_32.png -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/icons/OpenAPI_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit.openapi3/icons/OpenAPI_64.png -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.reprezen.swagedit.openapi3 4 | 5 | 6 | com.reprezen 7 | SwagEdit 8 | 0.8.0-SNAPSHOT 9 | ../pom.xml 10 | 11 | 12 | eclipse-plugin 13 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/resources/com.reprezen.swagedit.openapi3.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/assist/contexts/OperationContextType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.assist.contexts; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import java.util.List; 16 | 17 | import org.eclipse.core.runtime.IPath; 18 | 19 | import com.fasterxml.jackson.core.JsonPointer; 20 | import com.reprezen.swagedit.core.assist.ProposalDescriptor; 21 | import com.reprezen.swagedit.core.assist.contexts.SchemaContextType; 22 | import com.reprezen.swagedit.core.model.AbstractNode; 23 | import com.reprezen.swagedit.core.model.Model; 24 | import com.reprezen.swagedit.core.schema.CompositeSchema; 25 | import com.reprezen.swagedit.core.utils.URLUtils; 26 | 27 | /** 28 | * ContextType that collects proposals from operations pointers. 29 | */ 30 | public class OperationContextType extends SchemaContextType { 31 | 32 | private final JsonPointer operationPointer = JsonPointer.compile("/definitions/operation"); 33 | 34 | public OperationContextType(CompositeSchema schema, String regex) { 35 | super(schema, "operation", "operation", regex); 36 | } 37 | 38 | @Override 39 | public Collection collectProposals(Model model, IPath path) { 40 | final Collection results = new ArrayList<>(); 41 | final List nodes = model.findByType(operationPointer); 42 | 43 | for (AbstractNode node : nodes) { 44 | String pointer = node.getPointerString(); 45 | String basePath = (path != null ? path.toString() : "") + "#" + pointer; 46 | String key = node.getProperty(); 47 | String value = basePath; 48 | String encoded = URLUtils.encodeURL(value); 49 | 50 | results.add(new ProposalDescriptor(key).replacementString("\"" + encoded + "\"").type(value)); 51 | } 52 | 53 | return results; 54 | } 55 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/assist/contexts/OperationIdContextType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.assist.contexts; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import java.util.List; 16 | 17 | import org.eclipse.core.runtime.IPath; 18 | 19 | import com.fasterxml.jackson.core.JsonPointer; 20 | import com.reprezen.swagedit.core.assist.ProposalDescriptor; 21 | import com.reprezen.swagedit.core.assist.contexts.SchemaContextType; 22 | import com.reprezen.swagedit.core.model.AbstractNode; 23 | import com.reprezen.swagedit.core.model.Model; 24 | import com.reprezen.swagedit.core.schema.CompositeSchema; 25 | 26 | /** 27 | * ContextType that collects proposals from operations ids. 28 | */ 29 | public class OperationIdContextType extends SchemaContextType { 30 | 31 | private final JsonPointer operationPointer = JsonPointer.compile("/definitions/operation"); 32 | 33 | public OperationIdContextType(CompositeSchema schema, String regex) { 34 | super(schema, "operationId", "operationId", regex, true); 35 | } 36 | 37 | @Override 38 | public Collection collectProposals(Model model, IPath path) { 39 | final Collection results = new ArrayList<>(); 40 | final List nodes = model.findByType(operationPointer); 41 | 42 | for (AbstractNode node : nodes) { 43 | AbstractNode value = node.get("operationId"); 44 | if (value != null && value.asValue().getValue() instanceof String) { 45 | String key = (String) value.asValue().getValue(); 46 | results.add(new ProposalDescriptor(key).replacementString(key).type(value.getProperty())); 47 | } 48 | } 49 | return results; 50 | } 51 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/assist/contexts/SecuritySchemeContextType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.assist.contexts; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | 16 | import org.eclipse.core.runtime.IPath; 17 | 18 | import com.fasterxml.jackson.core.JsonPointer; 19 | import com.reprezen.swagedit.core.assist.ProposalDescriptor; 20 | import com.reprezen.swagedit.core.assist.contexts.SchemaContextType; 21 | import com.reprezen.swagedit.core.model.AbstractNode; 22 | import com.reprezen.swagedit.core.model.Model; 23 | import com.reprezen.swagedit.core.schema.CompositeSchema; 24 | 25 | /** 26 | * ContextType that collects proposals from security schemes names. 27 | */ 28 | public class SecuritySchemeContextType extends SchemaContextType { 29 | 30 | private final JsonPointer securityPointer = JsonPointer.compile("/components/securitySchemes"); 31 | 32 | public SecuritySchemeContextType(CompositeSchema schema, String regex) { 33 | super(schema, "securitySchemes", "securitySchemes", regex); 34 | } 35 | 36 | @Override 37 | public Collection collectProposals(Model model, IPath path) { 38 | final Collection results = new ArrayList<>(); 39 | AbstractNode securitySchemes = model.find(securityPointer); 40 | 41 | if (securitySchemes != null && securitySchemes.isObject()) { 42 | for (String key : securitySchemes.asObject().fieldNames()) { 43 | results.add(new ProposalDescriptor(key).replacementString(key).type(securitySchemes.getProperty())); 44 | } 45 | } 46 | 47 | return results; 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/assist/ext/CallbacksContentAssistExt.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2017 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.assist.ext; 12 | 13 | import java.util.Arrays; 14 | import java.util.Collection; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | import com.reprezen.swagedit.core.assist.ProposalDescriptor; 18 | import com.reprezen.swagedit.core.assist.ext.ContentAssistExt; 19 | import com.reprezen.swagedit.core.model.AbstractNode; 20 | import com.reprezen.swagedit.core.schema.TypeDefinition; 21 | 22 | public class CallbacksContentAssistExt implements ContentAssistExt { 23 | 24 | private final JsonPointer pointer = JsonPointer.compile("/definitions/callbacks"); 25 | 26 | @Override 27 | public boolean canProvideContentAssist(TypeDefinition type) { 28 | return type != null && pointer.equals(type.getPointer()); 29 | } 30 | 31 | @Override 32 | public Collection getProposals(TypeDefinition type, AbstractNode node, String prefix) { 33 | return Arrays.asList( // 34 | new ProposalDescriptor("x-:").replacementString("x-").type("specificationExtension")); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/assist/ext/ParameterInContentAssistExt.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2017 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.assist.ext; 12 | 13 | import java.util.Arrays; 14 | import java.util.Collection; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | import com.reprezen.swagedit.core.assist.ProposalDescriptor; 18 | import com.reprezen.swagedit.core.assist.ext.ContentAssistExt; 19 | import com.reprezen.swagedit.core.model.AbstractNode; 20 | import com.reprezen.swagedit.core.schema.TypeDefinition; 21 | 22 | public class ParameterInContentAssistExt implements ContentAssistExt { 23 | 24 | private static final String description = "The location of the parameter. Possible values are \"query\", \"header\", \"path\" or \"cookie\""; 25 | private static final JsonPointer pointer = JsonPointer.compile("/definitions/parameter/properties/in"); 26 | 27 | @Override 28 | public boolean canProvideContentAssist(TypeDefinition type) { 29 | return type != null && pointer.equals(type.getPointer()); 30 | } 31 | 32 | @Override 33 | public Collection getProposals(TypeDefinition type, AbstractNode node, String prefix) { 34 | return Arrays.asList( // 35 | new ProposalDescriptor("query").replacementString("query").description(description).type("string"), 36 | new ProposalDescriptor("header").replacementString("header").description(description).type("string"), 37 | new ProposalDescriptor("path").replacementString("path").description(description).type("string"), 38 | new ProposalDescriptor("cookie").replacementString("cookie").description(description).type("string")); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/assist/ext/SchemaTypeContentAssistExt.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2017 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.assist.ext; 12 | 13 | import java.util.Arrays; 14 | import java.util.Collection; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | import com.reprezen.swagedit.core.assist.ProposalDescriptor; 18 | import com.reprezen.swagedit.core.assist.ext.ContentAssistExt; 19 | import com.reprezen.swagedit.core.model.AbstractNode; 20 | import com.reprezen.swagedit.core.schema.TypeDefinition; 21 | 22 | public class SchemaTypeContentAssistExt implements ContentAssistExt { 23 | 24 | private static final JsonPointer pointer = JsonPointer.compile("/definitions/schema/properties/type"); 25 | 26 | @Override 27 | public boolean canProvideContentAssist(TypeDefinition type) { 28 | return type != null && pointer.equals(type.getPointer()); 29 | } 30 | 31 | @Override 32 | public Collection getProposals(TypeDefinition type, AbstractNode node, String prefix) { 33 | return Arrays.asList( // 34 | new ProposalDescriptor("array").replacementString("array").type("enum"), // 35 | new ProposalDescriptor("boolean").replacementString("boolean").type("enum"), // 36 | new ProposalDescriptor("integer").replacementString("integer").type("enum"), // 37 | new ProposalDescriptor("null").replacementString("\"null\"").type("enum"), // 38 | new ProposalDescriptor("number").replacementString("number").type("enum"), // 39 | new ProposalDescriptor("object").replacementString("object").type("enum"), // 40 | new ProposalDescriptor("string").replacementString("string").type("enum")); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/editor/OpenApi3ContentDescriber.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.editor; 12 | 13 | import java.util.regex.Pattern; 14 | 15 | import com.reprezen.swagedit.core.editor.TextContentDescriber; 16 | 17 | public class OpenApi3ContentDescriber extends TextContentDescriber { 18 | 19 | public static final String CONTENT_TYPE_ID = "com.reprezen.swagedit.contenttype.openapi3.yaml"; 20 | private final Pattern openApiV3Regex = Pattern.compile(".*openapi:\\s+([\"']?)3\\.0\\..+\\1.+", Pattern.DOTALL); 21 | 22 | @Override 23 | protected boolean isSupported(String content) { 24 | // should support arbitrary patch versions, e.g. `openapi: "3.0.0-RC0"` 25 | return openApiV3Regex.matcher(content).matches(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/editor/OpenApi3Document.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.editor; 12 | 13 | import com.reprezen.swagedit.core.editor.JsonDocument; 14 | import com.reprezen.swagedit.openapi3.Activator; 15 | import com.reprezen.swagedit.openapi3.schema.OpenApi3Schema; 16 | 17 | public class OpenApi3Document extends JsonDocument { 18 | 19 | public OpenApi3Document() { 20 | this(Activator.getDefault().getSchema()); 21 | } 22 | 23 | public OpenApi3Document(OpenApi3Schema schema) { 24 | super(schema); 25 | } 26 | 27 | @Override 28 | public Version getVersion() { 29 | return Version.OPENAPI; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/editor/OpenApi3DocumentProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.editor; 12 | 13 | import org.eclipse.jface.text.IDocument; 14 | 15 | import com.reprezen.swagedit.core.editor.JsonDocumentProvider; 16 | import com.reprezen.swagedit.openapi3.Activator; 17 | 18 | public class OpenApi3DocumentProvider extends JsonDocumentProvider { 19 | 20 | public OpenApi3DocumentProvider() { 21 | super(Activator.getDefault().getPreferenceStore()); 22 | } 23 | 24 | @Override 25 | protected IDocument createEmptyDocument() { 26 | return new OpenApi3Document(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/editor/wizard/NewOpenApiV3SpecWizard.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.editor.wizard; 12 | 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | 16 | import org.eclipse.jface.viewers.IStructuredSelection; 17 | import org.eclipse.ui.dialogs.WizardNewFileCreationPage; 18 | 19 | import com.reprezen.swagedit.core.wizard.NewFileWizard; 20 | import com.reprezen.swagedit.openapi3.Activator; 21 | import com.reprezen.swagedit.openapi3.editor.OpenApi3Editor; 22 | 23 | public class NewOpenApiV3SpecWizard extends NewFileWizard { 24 | 25 | @Override 26 | protected WizardNewFileCreationPage newFileCreationPage(IStructuredSelection selection) { 27 | return new NewOpenApiV3SpecWizardPage(selection); 28 | } 29 | 30 | public NewOpenApiV3SpecWizard() { 31 | super(OpenApi3Editor.ID); 32 | } 33 | 34 | private static class NewOpenApiV3SpecWizardPage extends WizardNewFileCreationPage { 35 | 36 | private final String extension = "yaml"; 37 | 38 | public NewOpenApiV3SpecWizardPage(IStructuredSelection selection) { 39 | super("SwagEditNewWizardPage", selection); 40 | setTitle("OpenAPI v3 Spec"); 41 | setDescription( 42 | "This wizard creates a new OpenAPI v3 Spec in YAML format, which can be opened in KaiZen Editor."); 43 | setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/openAPI_64.png")); 44 | setFileExtension(extension); 45 | } 46 | 47 | @Override 48 | protected InputStream getInitialContents() { 49 | try { 50 | return Activator.getDefault().getBundle().getEntry("/resources/default.yaml").openStream(); 51 | } catch (IOException e) { 52 | return null; 53 | } 54 | } 55 | 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/hyperlinks/LinkOperationHyperlinkDetector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.hyperlinks; 12 | 13 | import java.util.Iterator; 14 | import java.util.List; 15 | import java.util.Objects; 16 | 17 | import org.eclipse.jface.text.IRegion; 18 | import org.eclipse.jface.text.ITextViewer; 19 | import org.eclipse.jface.text.hyperlink.IHyperlink; 20 | 21 | import com.fasterxml.jackson.core.JsonPointer; 22 | import com.reprezen.swagedit.core.editor.JsonDocument; 23 | import com.reprezen.swagedit.core.hyperlinks.AbstractJsonHyperlinkDetector; 24 | import com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink; 25 | import com.reprezen.swagedit.core.model.AbstractNode; 26 | import com.reprezen.swagedit.core.model.Model; 27 | 28 | public class LinkOperationHyperlinkDetector extends AbstractJsonHyperlinkDetector { 29 | 30 | @Override 31 | protected boolean canDetect(JsonPointer pointer) { 32 | return pointer != null && pointer.toString().matches(".*/links/(\\w+)/operationId"); 33 | } 34 | 35 | @Override 36 | protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) { 37 | Model model = doc.getModel(); 38 | AbstractNode node = model.find(pointer); 39 | List nodes = model.findByType(JsonPointer.compile("/definitions/operation")); 40 | Iterator it = nodes.iterator(); 41 | 42 | AbstractNode found = null; 43 | while (it.hasNext() && found == null) { 44 | AbstractNode current = it.next(); 45 | AbstractNode value = current.get("operationId"); 46 | 47 | if (value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue())) { 48 | found = value; 49 | } 50 | } 51 | 52 | if (found != null) { 53 | IRegion target = doc.getRegion(found.getPointer()); 54 | if (target != null) { 55 | return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) }; 56 | } 57 | } 58 | 59 | return null; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/hyperlinks/LinkOperationRefHyperlinkDetector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.hyperlinks; 12 | 13 | import org.eclipse.core.resources.IFile; 14 | import org.eclipse.jface.text.IRegion; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | import com.reprezen.swagedit.core.hyperlinks.JsonFileHyperlink; 18 | import com.reprezen.swagedit.core.hyperlinks.ReferenceHyperlinkDetector; 19 | 20 | public class LinkOperationRefHyperlinkDetector extends ReferenceHyperlinkDetector { 21 | 22 | @Override 23 | protected JsonFileHyperlink createFileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) { 24 | return new OpenApi3FileHyperlink(linkRegion, label, file, pointer); 25 | } 26 | 27 | @Override 28 | protected boolean canDetect(JsonPointer pointer) { 29 | return pointer != null && pointer.toString().endsWith("operationRef"); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/hyperlinks/OpenApi3FileHyperlink.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.hyperlinks; 12 | 13 | import org.eclipse.core.resources.IFile; 14 | import org.eclipse.jface.text.IRegion; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | import com.reprezen.swagedit.core.editor.JsonDocument; 18 | import com.reprezen.swagedit.core.hyperlinks.JsonFileHyperlink; 19 | import com.reprezen.swagedit.openapi3.editor.OpenApi3Document; 20 | 21 | public class OpenApi3FileHyperlink extends JsonFileHyperlink { 22 | 23 | public OpenApi3FileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) { 24 | super(linkRegion, label, file, pointer); 25 | } 26 | 27 | @Override 28 | protected JsonDocument createDocument() { 29 | return new OpenApi3Document(); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/hyperlinks/OpenApi3ReferenceHyperlinkDetector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.hyperlinks; 12 | 13 | import org.eclipse.core.resources.IFile; 14 | import org.eclipse.jface.text.IRegion; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | import com.reprezen.swagedit.core.hyperlinks.JsonFileHyperlink; 18 | import com.reprezen.swagedit.core.hyperlinks.JsonReferenceHyperlinkDetector; 19 | 20 | public class OpenApi3ReferenceHyperlinkDetector extends JsonReferenceHyperlinkDetector { 21 | 22 | @Override 23 | protected JsonFileHyperlink createFileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) { 24 | return new OpenApi3FileHyperlink(linkRegion, label, file, pointer); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/hyperlinks/SecuritySchemeHyperlinkDetector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.hyperlinks; 12 | 13 | import java.util.regex.Matcher; 14 | import java.util.regex.Pattern; 15 | 16 | import org.eclipse.jface.text.IRegion; 17 | import org.eclipse.jface.text.ITextViewer; 18 | import org.eclipse.jface.text.hyperlink.IHyperlink; 19 | 20 | import com.fasterxml.jackson.core.JsonPointer; 21 | import com.reprezen.swagedit.core.editor.JsonDocument; 22 | import com.reprezen.swagedit.core.hyperlinks.AbstractJsonHyperlinkDetector; 23 | import com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink; 24 | import com.reprezen.swagedit.core.model.AbstractNode; 25 | import com.reprezen.swagedit.core.model.Model; 26 | 27 | public class SecuritySchemeHyperlinkDetector extends AbstractJsonHyperlinkDetector { 28 | 29 | protected static final String REGEX = ".*/security/\\d+/(\\w+)"; 30 | protected static final Pattern PATTERN = Pattern.compile(REGEX); 31 | 32 | @Override 33 | protected boolean canDetect(JsonPointer pointer) { 34 | return pointer != null && pointer.toString().matches(REGEX); 35 | } 36 | 37 | @Override 38 | protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) { 39 | Matcher matcher = PATTERN.matcher(pointer.toString()); 40 | String link = matcher.find() ? matcher.group(1) : null; 41 | 42 | if (link != null) { 43 | Model model = doc.getModel(); 44 | AbstractNode securityScheme = model.find("/components/securitySchemes/" + link); 45 | 46 | if (securityScheme != null) { 47 | IRegion target = doc.getRegion(securityScheme.getPointer()); 48 | if (target != null) { 49 | return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) }; 50 | } 51 | } 52 | } 53 | return null; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/preferences/OpenApi3PreferenceConstants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.preferences; 12 | 13 | public class OpenApi3PreferenceConstants { 14 | public static String ADVANCED_VALIDATION = "openapi.advanced.validation"; //$NON-NLS-1$ 15 | } 16 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/preferences/OpenApi3PreferenceInitializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.preferences; 12 | 13 | import static com.reprezen.swagedit.openapi3.preferences.OpenApi3PreferenceConstants.ADVANCED_VALIDATION; 14 | 15 | import java.util.Set; 16 | 17 | import org.eclipse.jface.preference.IPreferenceStore; 18 | 19 | import com.reprezen.swagedit.core.editor.JsonDocument.Version; 20 | import com.reprezen.swagedit.core.preferences.JsonPreferenceInitializer; 21 | import com.reprezen.swagedit.core.providers.PreferenceProvider; 22 | import com.reprezen.swagedit.core.utils.ExtensionUtils; 23 | import com.reprezen.swagedit.openapi3.Activator; 24 | 25 | public class OpenApi3PreferenceInitializer extends JsonPreferenceInitializer { 26 | 27 | @Override 28 | public void initializeDefaultPreferences() { 29 | IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 30 | setColorPreferences(store); 31 | store.setDefault(ADVANCED_VALIDATION, true); 32 | 33 | Set providers = ExtensionUtils.getPreferenceProviders(); 34 | providers.forEach(provider -> { 35 | provider.initializeDefaultPreferences(Version.OPENAPI, store); 36 | }); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/preferences/OpenApi3PreferencePage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.preferences; 12 | 13 | import com.reprezen.swagedit.core.preferences.KaizenPreferencePage; 14 | import com.reprezen.swagedit.openapi3.Activator; 15 | 16 | public class OpenApi3PreferencePage extends KaizenPreferencePage { 17 | 18 | public OpenApi3PreferencePage() { 19 | setDescription("KaiZen OpenAPI Editor preferences for OpenAPI v3"); 20 | setPreferenceStore(Activator.getDefault().getPreferenceStore()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/preferences/OpenApiColorPreferences.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.preferences; 12 | 13 | import org.dadacoalition.yedit.preferences.ColorPreferences; 14 | 15 | import com.reprezen.swagedit.openapi3.Activator; 16 | 17 | /* 18 | * This implementation of preference page overrides the YEdit implementation but 19 | * uses it's own preference store. 20 | * 21 | */ 22 | public class OpenApiColorPreferences extends ColorPreferences { 23 | 24 | public OpenApiColorPreferences() { 25 | super(); 26 | setPreferenceStore(Activator.getDefault().getPreferenceStore()); 27 | setDescription("Swagger Color Preferences for syntax highlighting"); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/preferences/OpenApiTemplatePreferences.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.preferences; 12 | 13 | import com.reprezen.swagedit.core.preferences.KaizenTemplatePreferences; 14 | import com.reprezen.swagedit.openapi3.Activator; 15 | import com.reprezen.swagedit.openapi3.editor.OpenApi3Editor; 16 | 17 | public class OpenApiTemplatePreferences extends KaizenTemplatePreferences { 18 | 19 | public OpenApiTemplatePreferences() { 20 | super(new OpenApi3Editor.OpenApi3SourceViewerConfiguration(), Activator.getDefault().getPreferenceStore(), 21 | Activator.getDefault().getTemplateStore(), Activator.getDefault().getContextTypeRegistry()); 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.openapi3/src/com/reprezen/swagedit/openapi3/schema/OpenApi3Schema.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.openapi3.schema; 12 | 13 | import java.io.IOException; 14 | 15 | import com.fasterxml.jackson.core.JsonPointer; 16 | import com.fasterxml.jackson.databind.JsonNode; 17 | import com.reprezen.swagedit.core.schema.CompositeSchema; 18 | import com.reprezen.swagedit.core.schema.JsonSchema; 19 | import com.reprezen.swagedit.core.schema.ObjectTypeDefinition; 20 | 21 | public class OpenApi3Schema extends CompositeSchema { 22 | 23 | public static final String URL = "http://openapis.org/v3/schema.json"; 24 | 25 | private JsonSchema coreType; 26 | 27 | public OpenApi3Schema() { 28 | 29 | JsonNode core; 30 | try { 31 | core = mapper.readTree(getClass().getResourceAsStream("core.json")); 32 | } catch (IOException e) { 33 | return; 34 | } 35 | 36 | JsonNode content; 37 | try { 38 | content = mapper.readTree(getClass().getResourceAsStream("schema_v3.json")); 39 | } catch (IOException e) { 40 | return; 41 | } 42 | 43 | coreType = new JsonSchema(core, this); 44 | coreType.setType(new ObjectTypeDefinition(coreType, JsonPointer.compile(""), core)); 45 | 46 | swaggerType = new JsonSchema(content, this); 47 | swaggerType.setType(new ObjectTypeDefinition(swaggerType, JsonPointer.compile(""), content)); 48 | 49 | } 50 | 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.repository/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.reprezen.swagedit.repository 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.xtext.ui.shared.xtextNature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.repository/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.repository/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.repository/category.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.repository/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.reprezen 6 | SwagEdit 7 | 0.8.0-SNAPSHOT 8 | 9 | com.reprezen.swagedit.repository 10 | com.reprezen.swagedit.repository 11 | eclipse-repository 12 | 13 | 14 | 15 | 16 | org.eclipse.tycho 17 | tycho-p2-repository-plugin 18 | ${tycho.version} 19 | 20 | true 21 | true 22 | true 23 | false 24 | 25 | 26 | 27 | 28 | org.eclipse.tycho 29 | tycho-p2-publisher-plugin 30 | ${tycho.version} 31 | 32 | true 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.target/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.reprezen 6 | SwagEdit 7 | 0.8.0-SNAPSHOT 8 | 9 | com.reprezen.swagedit.target 10 | eclipse-target-definition 11 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.reprezen.swagedit.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.m2e.core.maven2Nature 36 | org.eclipse.pde.PluginNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.xtext.ui.shared.xtextNature 39 | 40 | 41 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: KaiZen Editor Tests 4 | Bundle-SymbolicName: com.reprezen.swagedit.tests 5 | Bundle-Version: 0.8.0.qualifier 6 | Fragment-Host: com.reprezen.swagedit;bundle-version="0.8.0" 7 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 8 | Require-Bundle: org.junit;bundle-version="4.0.0", 9 | org.eclipse.xtend.lib, 10 | org.mockito;bundle-version="1.9.5", 11 | org.hamcrest;bundle-version="1.1.0" 12 | Bundle-ClassPath: . 13 | Bundle-Vendor: ModelSolv, Inc. d.b.a. RepreZen 14 | Automatic-Module-Name: com.reprezen.swagedit.tests 15 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = .,\ 2 | META-INF/ 3 | jars.compile.order = . 4 | source.. = src/,\ 5 | xtend-gen/ 6 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | com.reprezen 7 | SwagEdit 8 | 0.8.0-SNAPSHOT 9 | ../pom.xml 10 | 11 | 12 | com.reprezen.swagedit.tests 13 | eclipse-test-plugin 14 | 15 | 16 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/resources/error-1.json: -------------------------------------------------------------------------------- 1 | { 2 | "level": "error", 3 | "schema": { 4 | "loadingURI": "#", 5 | "pointer": "" 6 | }, 7 | "instance": { 8 | "pointer": "" 9 | }, 10 | "domain": "validation", 11 | "keyword": "additionalProperties", 12 | "message": "object instance has properties which are not allowed by the schema: [\"domain\",\"instance\",\"keyword\",\"level\",\"matched\",\"message\",\"nrSchemas\",\"reports\",\"schema\"]", 13 | "unwanted": [ 14 | "domain", 15 | "instance", 16 | "keyword", 17 | "level", 18 | "matched", 19 | "message", 20 | "nrSchemas", 21 | "reports", 22 | "schema" 23 | ] 24 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/src/com/reprezen/swagedit/editor/hyperlinks/DefinitionHyperlinkDetectorTest.xtend: -------------------------------------------------------------------------------- 1 | package com.reprezen.swagedit.editor.hyperlinks 2 | 3 | import com.reprezen.swagedit.editor.SwaggerDocument 4 | import com.reprezen.swagedit.mocks.Mocks 5 | import java.util.Arrays 6 | import org.eclipse.jface.text.BadLocationException 7 | import org.eclipse.jface.text.ITextViewer 8 | import org.eclipse.jface.text.Region 9 | import org.junit.Test 10 | 11 | import static org.hamcrest.core.IsCollectionContaining.hasItem 12 | import static org.junit.Assert.* 13 | import com.reprezen.swagedit.core.hyperlinks.DefinitionHyperlinkDetector 14 | import com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink 15 | 16 | class DefinitionHyperlinkDetectorTest { 17 | 18 | val detector = new DefinitionHyperlinkDetector() 19 | 20 | @Test 21 | def void testShouldCreateHyperLink_ToDefinition() throws BadLocationException { 22 | val document = new SwaggerDocument() 23 | val ITextViewer viewer = Mocks.mockTextViewer(document) 24 | 25 | val text = ''' 26 | tags: 27 | - foo 28 | definitions: 29 | foo: 30 | type: object 31 | ''' 32 | 33 | document.set(text) 34 | 35 | // region that includes `- foo` 36 | val region = new Region("tags:\n - fo".length(), 1) 37 | val hyperlinks = detector.detectHyperlinks(viewer, region, false); 38 | 39 | // expected region 40 | val linkRegion = new Region(document.getLineOffset(1) + " - ".length(), 3) 41 | val targetRegion = new Region(29, 7) 42 | 43 | assertThat(Arrays.asList(hyperlinks), hasItem(new SwaggerHyperlink("foo", viewer, linkRegion, targetRegion))) 44 | } 45 | 46 | @Test 47 | def void testShouldCreateHyperLink_FromRequired_ToProperty() throws BadLocationException { 48 | val document = new SwaggerDocument() 49 | val ITextViewer viewer = Mocks.mockTextViewer(document) 50 | 51 | val text = ''' 52 | NewPet: 53 | required: 54 | - name 55 | properties: 56 | name: 57 | type: string 58 | ''' 59 | 60 | document.set(text) 61 | // region that includes `- name` 62 | val region = new Region("NewPet:\nrequired:\n - nam".length(), 1) 63 | val hyperlinks = detector.detectHyperlinks(viewer, region, false) 64 | 65 | // expected region 66 | val linkRegion = new Region(document.getLineOffset(2) + " - ".length(), "name".length()) 67 | val targetRegion = new Region(45, 10) 68 | 69 | assertThat(Arrays.asList(hyperlinks), hasItem(new SwaggerHyperlink("name", viewer, linkRegion, targetRegion))) 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/src/com/reprezen/swagedit/editor/hyperlinks/PathParamHyperlinkDetectorTest.xtend: -------------------------------------------------------------------------------- 1 | package com.reprezen.swagedit.editor.hyperlinks 2 | 3 | import com.reprezen.swagedit.editor.SwaggerDocument 4 | import com.reprezen.swagedit.mocks.Mocks 5 | import java.util.Arrays 6 | import java.util.HashSet 7 | import org.eclipse.jface.text.Region 8 | import org.junit.Test 9 | 10 | import static org.hamcrest.core.IsCollectionContaining.hasItem 11 | import static org.hamcrest.core.IsCollectionContaining.hasItems 12 | import static org.junit.Assert.assertThat 13 | import com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink 14 | import com.reprezen.swagedit.core.hyperlinks.PathParamHyperlinkDetector 15 | 16 | class PathParamHyperlinkDetectorTest { 17 | 18 | val detector = new PathParamHyperlinkDetector 19 | 20 | @Test 21 | def void testShouldCreateHyperLink_FromPathParameter_ToParameterDefinition() throws Exception { 22 | val document = new SwaggerDocument() 23 | val viewer = Mocks.mockTextViewer(document) 24 | 25 | val text = ''' 26 | paths: 27 | /{id}: 28 | get: 29 | parameters: 30 | - name: id 31 | type: number 32 | required: true 33 | in: path 34 | ''' 35 | 36 | document.set(text); 37 | // region that includes `/{id}:` 38 | val region = new Region(11, 1) 39 | val hyperlinks = detector.detectHyperlinks(viewer, region, false) 40 | 41 | // expected region 42 | val linkRegion = new Region(document.getLineOffset(1) + " /".length(), "{id}".length()) 43 | val targetRegion = new Region(43, 19) 44 | 45 | assertThat(Arrays.asList(hyperlinks), hasItem(new SwaggerHyperlink("id : get", viewer, linkRegion, targetRegion))); 46 | } 47 | 48 | @Test 49 | def void test_match_paramter() { 50 | val text = "/path/{id}" 51 | 52 | val matcher = PathParamHyperlinkDetector.PARAMETER_PATTERN.matcher(text) 53 | val groups = new HashSet() 54 | while (matcher.find()) { 55 | groups.add(matcher.group(1)) 56 | } 57 | 58 | assertThat(groups, hasItems("id")) 59 | } 60 | 61 | @Test 62 | def void test_match_second_paramter() { 63 | val text = "/path/{id}/other/{foo}" 64 | 65 | val matcher = PathParamHyperlinkDetector.PARAMETER_PATTERN.matcher(text) 66 | val groups = new HashSet() 67 | while (matcher.find()) { 68 | groups.add(matcher.group(1)) 69 | } 70 | 71 | assertThat(groups, hasItems("id", "foo")) 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/src/com/reprezen/swagedit/tests/utils/Cursors.xtend: -------------------------------------------------------------------------------- 1 | package com.reprezen.swagedit.tests.utils 2 | 3 | import com.fasterxml.jackson.core.JsonPointer 4 | import com.reprezen.swagedit.editor.SwaggerDocument 5 | import com.reprezen.swagedit.mocks.Mocks 6 | import java.util.HashMap 7 | import org.eclipse.jface.text.Document 8 | import org.eclipse.jface.text.IRegion 9 | import org.eclipse.jface.text.Region 10 | import org.eclipse.jface.text.contentassist.ICompletionProposal 11 | import org.eclipse.jface.text.contentassist.IContentAssistProcessor 12 | import org.eclipse.xtext.xbase.lib.Functions.Function2 13 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure2 14 | 15 | import static org.junit.Assert.* 16 | 17 | class Cursors { 18 | 19 | static def (String, String)=>void setUpPathTest(String yaml, SwaggerDocument doc) { 20 | val groups = groupMarkers(yaml) 21 | doc.set(removeMarkers(yaml)) 22 | doc.onChange 23 | 24 | new Procedure2() { 25 | override apply(String path, String marker) { 26 | assertEquals(JsonPointer.compile(path), doc.getPath(groups.get(marker))) 27 | } 28 | } 29 | } 30 | 31 | static def (IContentAssistProcessor, String)=>ICompletionProposal[] setUpContentAssistTest(String yaml, 32 | SwaggerDocument doc) { 33 | 34 | val groups = groupMarkers(yaml) 35 | doc.set(removeMarkers(yaml)) 36 | doc.onChange 37 | 38 | new Function2() { 39 | override ICompletionProposal[] apply(IContentAssistProcessor processor, String marker) { 40 | // TODO check why we need to add +1 to offset here 41 | val offset = groups.get(marker).offset + 1 42 | val viewer = Mocks.mockTextViewer(doc, offset) 43 | 44 | processor.computeCompletionProposals(viewer, offset) 45 | } 46 | } 47 | } 48 | 49 | static def groupMarkers(String text) { 50 | val groups = new HashMap 51 | 52 | val doc = new Document(text) 53 | var i = 0 54 | var offset = 0 55 | var start = false 56 | var group = "" 57 | 58 | while (i < doc.getLength()) { 59 | var current = doc.get(i, 1) 60 | if (current.equals("<")) { 61 | start = true 62 | } else if (current.equals(">")) { 63 | start = false 64 | groups.put(group, new Region(Math.max(0, offset - 1), 1)) 65 | group = "" 66 | } else { 67 | if (start) { 68 | group += current 69 | } else { 70 | offset++ 71 | } 72 | } 73 | i++ 74 | } 75 | 76 | groups 77 | } 78 | 79 | protected static def removeMarkers(String content) { 80 | content.replaceAll("<\\d+>", "") 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/src/com/reprezen/swagedit/tests/utils/PointerHelpers.xtend: -------------------------------------------------------------------------------- 1 | package com.reprezen.swagedit.tests.utils 2 | 3 | import com.fasterxml.jackson.core.JsonPointer 4 | 5 | class PointerHelpers { 6 | def ptr(String s) { JsonPointer.compile(s) } 7 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/src/com/reprezen/swagedit/validation/ErrorProcessorTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.validation; 12 | 13 | import static com.google.common.collect.Iterables.getOnlyElement; 14 | import static org.junit.Assert.assertEquals; 15 | import static org.junit.Assert.assertTrue; 16 | 17 | import java.nio.file.Paths; 18 | import java.util.Set; 19 | 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | import org.yaml.snakeyaml.nodes.Node; 23 | 24 | import com.fasterxml.jackson.databind.JsonNode; 25 | import com.fasterxml.jackson.databind.ObjectMapper; 26 | import com.reprezen.swagedit.core.validation.ErrorProcessor; 27 | import com.reprezen.swagedit.core.validation.SwaggerError; 28 | 29 | public class ErrorProcessorTest { 30 | 31 | private ErrorProcessor processor; 32 | private ObjectMapper mapper = new ObjectMapper(); 33 | 34 | @Before 35 | public void setUp() { 36 | Node document = null; 37 | processor = new ErrorProcessor(document, null); 38 | } 39 | 40 | @Test 41 | public void testProcessNode_WithSingleError() throws Exception { 42 | JsonNode fixture = mapper.readTree(Paths.get("resources", "error-1.json").toFile()); 43 | Set errors = processor.processMessageNode(fixture); 44 | 45 | assertEquals(1, errors.size()); 46 | assertTrue(getOnlyElement(errors) instanceof SwaggerError); 47 | } 48 | 49 | @Test 50 | public void testProcessNode_WithOneOfError() throws Exception { 51 | JsonNode fixture = mapper.readTree(Paths.get("resources", "error-2.json").toFile()); 52 | Set errors = processor.processMessageNode(fixture); 53 | 54 | assertEquals(1, errors.size()); 55 | assertTrue(getOnlyElement(errors) instanceof SwaggerError.MultipleSwaggerError); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /com.reprezen.swagedit.tests/src/com/reprezen/swagedit/validation/YamlErrorProcessorTest.xtend: -------------------------------------------------------------------------------- 1 | package com.reprezen.swagedit.validation 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper 4 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory 5 | import com.reprezen.swagedit.core.validation.Messages 6 | import com.reprezen.swagedit.core.validation.YamlErrorProcessor 7 | import org.junit.Test 8 | 9 | import static org.junit.Assert.* 10 | 11 | class YamlErrorProcessorTest { 12 | 13 | val processor = new YamlErrorProcessor 14 | 15 | @Test 16 | def void testIndentationError() { 17 | val content = ''' 18 | openapi: "3.0.0" 19 | info: 20 | version: 1.0.0 21 | title: Swagger Petstore 22 | paths: {} 23 | components: 24 | schemas: 25 | Pet: 26 | required: 27 | - id 28 | properties: 29 | id: 30 | type: integer 31 | format: int64 32 | name: 33 | type: string 34 | ''' 35 | 36 | var mapper = new ObjectMapper(new YAMLFactory) 37 | try { 38 | mapper.readTree(content) 39 | fail() 40 | } catch (Exception e) { 41 | assertEquals(Messages.error_yaml_parser_indentation, processor.rewriteMessage(e)) 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.reprezen.swagedit 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.xtext.ui.shared.xtextNature 36 | org.eclipse.m2e.core.maven2Nature 37 | org.eclipse.pde.PluginNature 38 | org.eclipse.jdt.core.javanature 39 | 40 | 41 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 -------------------------------------------------------------------------------- /com.reprezen.swagedit/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: %Bundle-Name 4 | Bundle-Localization: OSGI-INF/l10n/bundle 5 | Bundle-SymbolicName: com.reprezen.swagedit;singleton:=true 6 | Bundle-Version: 0.8.0.qualifier 7 | Require-Bundle: org.eclipse.ui, 8 | org.eclipse.core.runtime, 9 | org.eclipse.core.filesystem, 10 | org.eclipse.ui.editors, 11 | org.eclipse.jface.text, 12 | org.eclipse.ui.views, 13 | org.eclipse.core.resources, 14 | org.eclipse.ui.ide, 15 | org.dadacoalition.yedit, 16 | com.github.eclipsecolortheme;resolution:=optional, 17 | com.reprezen.swagedit.core, 18 | com.reprezen.swagedit.dependencies;bundle-version="0.8.0" 19 | Bundle-ActivationPolicy: lazy 20 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 21 | Bundle-ClassPath: . 22 | Bundle-Activator: com.reprezen.swagedit.Activator 23 | Export-Package: com.reprezen.swagedit, 24 | com.reprezen.swagedit.assist, 25 | com.reprezen.swagedit.editor, 26 | com.reprezen.swagedit.editor.hyperlinks, 27 | com.reprezen.swagedit.preferences, 28 | com.reprezen.swagedit.schema, 29 | com.reprezen.swagedit.templates, 30 | com.reprezen.swagedit.validation, 31 | com.reprezen.swagedit.wizards 32 | Bundle-Vendor: ModelSolv, Inc. d.b.a. RepreZen 33 | Automatic-Module-Name: com.reprezen.swagedit 34 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/OSGI-INF/l10n/bundle.properties: -------------------------------------------------------------------------------- 1 | # Properties file for com.reprezen.swagedit 2 | category.name = KaiZen OpenAPI Editor 3 | wizard.name = Swagger v2 Spec 4 | editor.name = Swagger Editor 5 | content-type.name = Swagger v2 Content Type 6 | preferences.top-page.name = KaiZen 7 | preferences.page.name = Swagger v2 8 | preferences.page.colors.name = Color Preferences 9 | preferences.page.templates.name = Templates 10 | preferences.page.validation.name = Validation 11 | Bundle-Name = KaiZen OpenAPI Editor for Swagger v2 -------------------------------------------------------------------------------- /com.reprezen.swagedit/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = .,\ 2 | META-INF/,\ 3 | plugin.xml,\ 4 | icons/,\ 5 | resources/,\ 6 | OSGI-INF/ 7 | jars.compile.order = . 8 | source.. = src/ 9 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/icons/swagger_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit/icons/swagger_16.png -------------------------------------------------------------------------------- /com.reprezen.swagedit/icons/swagger_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit/icons/swagger_24.png -------------------------------------------------------------------------------- /com.reprezen.swagedit/icons/swagger_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit/icons/swagger_32.png -------------------------------------------------------------------------------- /com.reprezen.swagedit/icons/swagger_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/com.reprezen.swagedit/icons/swagger_64.png -------------------------------------------------------------------------------- /com.reprezen.swagedit/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | com.reprezen 7 | SwagEdit 8 | 0.8.0-SNAPSHOT 9 | ../pom.xml 10 | 11 | 12 | com.reprezen.swagedit 13 | eclipse-plugin 14 | 15 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/resources/com.reprezen.swagedit.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/resources/default.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # This is a sample Swagger spec, describing a simple API as a starting point. 3 | swagger: "2.0" 4 | info: 5 | description: Tax Blaster 6 | version: 1.0.0 7 | title: TaxBlaster 8 | host: taxblaster.com 9 | basePath: /api 10 | schemes: 11 | - http 12 | 13 | # Tags organize operations into groups for presentation in the Swagger UI. 14 | # Each tag has an optional description, which the Swagger UI will display in 15 | # the tag group header. 16 | tags: 17 | - name: TaxFilingObject 18 | description: An individual Tax Filing record, accessed by its ID 19 | 20 | paths: 21 | 22 | # Each Path Item Object describes a resource, containing a set of operations 23 | # at a specified path. The Path Item object can define parameters and 24 | # responses common all of its contained operations. 25 | /taxFilings/{id}: 26 | 27 | # Operations are identified by an HTTP method. 28 | get: 29 | tags: 30 | - TaxFilingObject 31 | description: Retrieves a tax filing having the specified id. 32 | operationId: getTaxFiling 33 | consumes: 34 | - application/json 35 | produces: 36 | - application/json 37 | parameters: 38 | - name: id 39 | in: path 40 | description: ID of the requested TaxFiling 41 | required: true 42 | type: string 43 | responses: 44 | 200: 45 | description: Successful response, with a representation of the Tax Filing. 46 | schema: 47 | # Reference to a Schema Object described in 'definitions' section 48 | $ref: "#/definitions/TaxFilingObject" 49 | examples: 50 | # Example message, keyed by media type 51 | application/json : 52 | { 53 | filingID : "1234", 54 | jurisdiction : Federal, 55 | year : "2015-10-02", 56 | currency : EUR, 57 | grossIncome : 74832, 58 | taxLiability : 15640 59 | } 60 | 404: 61 | description: The requested tax filing was not found. 62 | 63 | # The definitions section contains a set of named Schema Objects. Each schema 64 | # object describes a reusable data type, which can be reference by name. 65 | definitions: 66 | TaxFilingObject: 67 | type: object 68 | description: An individual Tax Filing record. 69 | properties: 70 | filingID: 71 | type: string 72 | jurisdiction: 73 | type: string 74 | year: 75 | type: string 76 | format: date 77 | period: 78 | type: integer 79 | currency: 80 | type: string 81 | grossIncome: 82 | type: number 83 | taxLiability: 84 | type: number 85 | taxpayer: 86 | type: object 87 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/Messages.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit; 12 | 13 | import org.eclipse.osgi.util.NLS; 14 | 15 | public class Messages extends NLS { 16 | 17 | private static final String BUNDLE_NAME = "com.reprezen.swagedit.messages"; 18 | 19 | // UI 20 | public static String swagedit_wizard_title; 21 | public static String swagedit_wizard_description; 22 | 23 | 24 | static { 25 | NLS.initializeMessages(BUNDLE_NAME, Messages.class); 26 | } 27 | 28 | private Messages() { 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/assist/SwaggerContentAssistProcessor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.assist; 12 | 13 | import org.eclipse.jface.text.contentassist.ContentAssistant; 14 | import org.eclipse.jface.text.templates.ContextTypeRegistry; 15 | import org.eclipse.jface.text.templates.persistence.TemplateStore; 16 | 17 | import com.reprezen.swagedit.Activator; 18 | import com.reprezen.swagedit.core.assist.JsonContentAssistProcessor; 19 | import com.reprezen.swagedit.core.assist.JsonProposalProvider; 20 | import com.reprezen.swagedit.core.assist.ext.MediaTypeContentAssistExt; 21 | import com.reprezen.swagedit.core.assist.ext.ResponseCodeContentAssistExt; 22 | import com.reprezen.swagedit.core.model.Model; 23 | import com.reprezen.swagedit.templates.SwaggerContextType; 24 | 25 | /** 26 | * This class provides basic content assist based on keywords used by the 27 | * swagger schema. 28 | */ 29 | public class SwaggerContentAssistProcessor extends JsonContentAssistProcessor { 30 | 31 | private static final JsonProposalProvider proposalProvider = new JsonProposalProvider(// 32 | new MediaTypeContentAssistExt(), // 33 | new ResponseCodeContentAssistExt()); 34 | 35 | public SwaggerContentAssistProcessor(ContentAssistant ca) { 36 | super(ca, proposalProvider, new SwaggerReferenceProposalProvider()); 37 | } 38 | 39 | @Override 40 | protected TemplateStore getTemplateStore() { 41 | return Activator.getDefault().getTemplateStore(); 42 | } 43 | 44 | @Override 45 | protected ContextTypeRegistry getContextTypeRegistry() { 46 | return Activator.getDefault().getContextTypeRegistry(); 47 | } 48 | 49 | @Override 50 | protected String getContextTypeId(Model model, String path) { 51 | return SwaggerContextType.getContextType(path); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/assist/SwaggerReferenceProposalProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.assist; 12 | 13 | import java.util.Arrays; 14 | 15 | import com.reprezen.swagedit.core.assist.JsonReferenceProposalProvider; 16 | import com.reprezen.swagedit.core.assist.contexts.ContextType; 17 | import com.reprezen.swagedit.core.assist.contexts.ContextTypeCollection; 18 | import com.reprezen.swagedit.core.assist.contexts.RegexContextType; 19 | import com.reprezen.swagedit.editor.SwaggerContentDescriber; 20 | 21 | /** 22 | * Completion proposal provider for JSON references. 23 | */ 24 | public class SwaggerReferenceProposalProvider extends JsonReferenceProposalProvider { 25 | 26 | public SwaggerReferenceProposalProvider() { 27 | super(SWAGGER_CONTEXT_TYPES, SwaggerContentDescriber.CONTENT_TYPE_ID); 28 | } 29 | 30 | protected static final String SCHEMA_DEFINITION_REGEX = "^/definitions/(\\w+/)+\\$ref|.*schema/(\\w+/)?\\$ref"; 31 | protected static final String RESPONSE_REGEX = ".*responses/(\\d{3}|default)/\\$ref"; 32 | protected static final String PARAMETER_REGEX = ".*/parameters/\\d+/\\$ref"; 33 | protected static final String PATH_ITEM_REGEX = "/paths/~1[^/]+/\\$ref"; 34 | 35 | 36 | public static final ContextType SCHEMA_DEFINITION = new RegexContextType("definitions", "schemas", 37 | SCHEMA_DEFINITION_REGEX); 38 | public static final ContextType PATH_ITEM = new RegexContextType("paths", "path items", PATH_ITEM_REGEX); 39 | public static final ContextType PATH_PARAMETER = new RegexContextType("parameters", "parameters", PARAMETER_REGEX); 40 | public static final ContextType PATH_RESPONSE = new RegexContextType("responses", "responses", RESPONSE_REGEX); 41 | 42 | public static final ContextTypeCollection SWAGGER_CONTEXT_TYPES = ContextType 43 | .newContentTypeCollection(Arrays.asList( // 44 | SCHEMA_DEFINITION, // 45 | PATH_ITEM, // 46 | PATH_PARAMETER, // 47 | PATH_RESPONSE)); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/editor/SwaggerContentDescriber.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.editor; 12 | 13 | import java.util.regex.Pattern; 14 | 15 | import com.reprezen.swagedit.core.editor.TextContentDescriber; 16 | 17 | public class SwaggerContentDescriber extends TextContentDescriber { 18 | 19 | public static final String CONTENT_TYPE_ID = "com.reprezen.swagedit.contenttype.swagger.yaml"; 20 | 21 | private final Pattern swaggerV2Regex = Pattern.compile(".*swagger:\\s+([\"'])2\\.0\\1.+", Pattern.DOTALL); 22 | 23 | @Override 24 | protected boolean isSupported(String content) { 25 | return swaggerV2Regex.matcher(content).matches(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/editor/SwaggerDocument.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.editor; 12 | 13 | import com.reprezen.swagedit.Activator; 14 | import com.reprezen.swagedit.core.editor.JsonDocument; 15 | import com.reprezen.swagedit.schema.SwaggerSchema; 16 | 17 | /** 18 | * SwaggerDocument 19 | * 20 | */ 21 | public class SwaggerDocument extends JsonDocument { 22 | 23 | public SwaggerDocument() { 24 | super(Activator.getDefault() != null ? Activator.getDefault().getSchema() : new SwaggerSchema()); 25 | } 26 | 27 | @Override 28 | public Version getVersion() { 29 | return Version.SWAGGER; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/editor/SwaggerDocumentProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.editor; 12 | 13 | import org.eclipse.jface.text.IDocument; 14 | 15 | import com.reprezen.swagedit.Activator; 16 | import com.reprezen.swagedit.core.editor.JsonDocumentProvider; 17 | 18 | public class SwaggerDocumentProvider extends JsonDocumentProvider { 19 | 20 | public SwaggerDocumentProvider() { 21 | super(Activator.getDefault().getPreferenceStore()); 22 | } 23 | 24 | @Override 25 | protected IDocument createEmptyDocument() { 26 | return new SwaggerDocument(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/editor/SwaggerReconcilingStrategy.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.editor; 12 | 13 | import com.reprezen.swagedit.core.editor.JsonReconcilingStrategy; 14 | 15 | public class SwaggerReconcilingStrategy extends JsonReconcilingStrategy { 16 | } 17 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/editor/SwaggerSourceViewerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.reprezen.swagedit.editor; 2 | 3 | import org.eclipse.jface.preference.IPreferenceStore; 4 | import org.eclipse.jface.text.IInformationControlCreator; 5 | import org.eclipse.jface.text.contentassist.ContentAssistant; 6 | import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; 7 | import org.eclipse.jface.text.hyperlink.URLHyperlinkDetector; 8 | import org.eclipse.jface.text.source.ISourceViewer; 9 | 10 | import com.reprezen.swagedit.assist.SwaggerContentAssistProcessor; 11 | import com.reprezen.swagedit.core.assist.JsonContentAssistProcessor; 12 | import com.reprezen.swagedit.core.editor.JsonSourceViewerConfiguration; 13 | import com.reprezen.swagedit.core.hyperlinks.DefinitionHyperlinkDetector; 14 | import com.reprezen.swagedit.core.hyperlinks.PathParamHyperlinkDetector; 15 | import com.reprezen.swagedit.core.schema.CompositeSchema; 16 | import com.reprezen.swagedit.editor.hyperlinks.SwaggerReferenceHyperlinkDetector; 17 | 18 | public class SwaggerSourceViewerConfiguration extends JsonSourceViewerConfiguration { 19 | 20 | public SwaggerSourceViewerConfiguration(IPreferenceStore store) { 21 | super(store); 22 | } 23 | 24 | @Override 25 | protected JsonContentAssistProcessor createContentAssistProcessor(ContentAssistant ca) { 26 | return new SwaggerContentAssistProcessor(ca); 27 | } 28 | 29 | @Override 30 | public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { 31 | return new IHyperlinkDetector[] { new URLHyperlinkDetector(), // 32 | new SwaggerReferenceHyperlinkDetector(), // 33 | new PathParamHyperlinkDetector(), // 34 | new DefinitionHyperlinkDetector() }; 35 | } 36 | 37 | @Override 38 | protected CompositeSchema getSchema() { 39 | return com.reprezen.swagedit.Activator.getDefault().getSchema(); 40 | } 41 | 42 | @Override 43 | protected IInformationControlCreator getOutlineInformationControlCreator() { 44 | return getOutlineInformationControlCreator(SwaggerContentDescriber.CONTENT_TYPE_ID); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/editor/hyperlinks/SwaggerReferenceHyperlinkDetector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.editor.hyperlinks; 12 | 13 | import org.eclipse.core.resources.IFile; 14 | import org.eclipse.jface.text.IRegion; 15 | 16 | import com.fasterxml.jackson.core.JsonPointer; 17 | import com.reprezen.swagedit.core.editor.JsonDocument; 18 | import com.reprezen.swagedit.core.hyperlinks.JsonFileHyperlink; 19 | import com.reprezen.swagedit.core.hyperlinks.JsonReferenceHyperlinkDetector; 20 | import com.reprezen.swagedit.editor.SwaggerDocument; 21 | 22 | public class SwaggerReferenceHyperlinkDetector extends JsonReferenceHyperlinkDetector { 23 | 24 | @Override 25 | protected JsonFileHyperlink createFileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) { 26 | return new SwaggerFileHyperlink(linkRegion, label, file, pointer); 27 | } 28 | 29 | public static class SwaggerFileHyperlink extends JsonFileHyperlink { 30 | 31 | public SwaggerFileHyperlink(IRegion linkRegion, String label, IFile file, JsonPointer pointer) { 32 | super(linkRegion, label, file, pointer); 33 | } 34 | 35 | @Override 36 | protected JsonDocument createDocument() { 37 | return new SwaggerDocument(); 38 | } 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/messages.properties: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (c) 2016 ModelSolv, Inc. and others. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the Eclipse Public License v1.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.eclipse.org/legal/epl-v10.html 7 | # 8 | # Contributors: 9 | # ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | ############################################################################### 11 | # messages 12 | swagedit_wizard_title = Swagger Spec 13 | 14 | # wizard 15 | swagedit_wizard_description = This wizard creates a new Swagger Spec in YAML format, which can be opened in KaiZen Editor. 16 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/preferences/SwaggerColorPreferences.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.preferences; 12 | 13 | import org.dadacoalition.yedit.preferences.ColorPreferences; 14 | 15 | import com.reprezen.swagedit.Activator; 16 | 17 | /* 18 | * This implementation of preference page overrides the YEdit implementation but 19 | * uses it's own preference store. 20 | * 21 | */ 22 | public class SwaggerColorPreferences extends ColorPreferences { 23 | 24 | public SwaggerColorPreferences() { 25 | super(); 26 | 27 | setPreferenceStore(Activator.getDefault().getPreferenceStore()); 28 | setDescription("Swagger Color Preferences for syntax highlighting"); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/preferences/SwaggerPreferenceConstants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.preferences; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | public class SwaggerPreferenceConstants { 17 | 18 | public static String VALIDATION_REF_SECURITY_DEFINITIONS_OBJECT = "validation.ref.security_definitions"; //$NON-NLS-1$ 19 | public static String VALIDATION_REF_SECURITY_SCHEME_OBJECT = "validation.ref.security_scheme_object"; //$NON-NLS-1$ 20 | public static String VALIDATION_REF_SECURITY_REQUIREMENTS_ARRAY = "validation.ref.security_requirements_array"; //$NON-NLS-1$ 21 | public static String VALIDATION_REF_SECURITY_REQUIREMENT_OBJECT = "validation.ref.security_requirement_object"; //$NON-NLS-1$ 22 | 23 | public static final List ALL_VALIDATION_PREFS = Arrays.asList(// 24 | VALIDATION_REF_SECURITY_DEFINITIONS_OBJECT, // 25 | VALIDATION_REF_SECURITY_SCHEME_OBJECT, // 26 | VALIDATION_REF_SECURITY_REQUIREMENTS_ARRAY, // 27 | VALIDATION_REF_SECURITY_REQUIREMENT_OBJECT); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/preferences/SwaggerPreferenceInitializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.preferences; 12 | 13 | import static com.reprezen.swagedit.preferences.SwaggerPreferenceConstants.VALIDATION_REF_SECURITY_DEFINITIONS_OBJECT; 14 | import static com.reprezen.swagedit.preferences.SwaggerPreferenceConstants.VALIDATION_REF_SECURITY_REQUIREMENTS_ARRAY; 15 | import static com.reprezen.swagedit.preferences.SwaggerPreferenceConstants.VALIDATION_REF_SECURITY_REQUIREMENT_OBJECT; 16 | import static com.reprezen.swagedit.preferences.SwaggerPreferenceConstants.VALIDATION_REF_SECURITY_SCHEME_OBJECT; 17 | 18 | import java.util.Set; 19 | 20 | import org.eclipse.jface.preference.IPreferenceStore; 21 | 22 | import com.reprezen.swagedit.Activator; 23 | import com.reprezen.swagedit.core.editor.JsonDocument.Version; 24 | import com.reprezen.swagedit.core.preferences.JsonPreferenceInitializer; 25 | import com.reprezen.swagedit.core.providers.PreferenceProvider; 26 | import com.reprezen.swagedit.core.utils.ExtensionUtils; 27 | 28 | /* 29 | * SwagEdit default preference values. 30 | * 31 | */ 32 | public class SwaggerPreferenceInitializer extends JsonPreferenceInitializer { 33 | 34 | @Override 35 | public void initializeDefaultPreferences() { 36 | IPreferenceStore store = Activator.getDefault().getPreferenceStore(); 37 | setColorPreferences(store); 38 | 39 | store.setDefault(VALIDATION_REF_SECURITY_DEFINITIONS_OBJECT, false); 40 | store.setDefault(VALIDATION_REF_SECURITY_SCHEME_OBJECT, false); 41 | store.setDefault(VALIDATION_REF_SECURITY_REQUIREMENTS_ARRAY, false); 42 | store.setDefault(VALIDATION_REF_SECURITY_REQUIREMENT_OBJECT, false); 43 | 44 | Set providers = ExtensionUtils.getPreferenceProviders(); 45 | providers.forEach(provider -> { 46 | provider.initializeDefaultPreferences(Version.SWAGGER, store); 47 | }); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/preferences/SwaggerPreferencePage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.preferences; 12 | 13 | import com.reprezen.swagedit.Activator; 14 | import com.reprezen.swagedit.core.preferences.KaizenPreferencePage; 15 | 16 | public class SwaggerPreferencePage extends KaizenPreferencePage { 17 | 18 | public SwaggerPreferencePage() { 19 | setDescription("Swagger Preferences"); 20 | setPreferenceStore(Activator.getDefault().getPreferenceStore()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/preferences/SwaggerTemplatePreferences.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.preferences; 12 | 13 | import com.reprezen.swagedit.Activator; 14 | import com.reprezen.swagedit.core.preferences.KaizenTemplatePreferences; 15 | import com.reprezen.swagedit.editor.SwaggerSourceViewerConfiguration; 16 | 17 | public class SwaggerTemplatePreferences extends KaizenTemplatePreferences { 18 | 19 | public SwaggerTemplatePreferences() { 20 | super(new SwaggerSourceViewerConfiguration(Activator.getDefault().getPreferenceStore()), 21 | Activator.getDefault().getPreferenceStore(), Activator.getDefault().getTemplateStore(), 22 | Activator.getDefault().getContextTypeRegistry()); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/validation/SwaggerValidator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.validation; 12 | 13 | import java.util.HashMap; 14 | 15 | import org.eclipse.jface.preference.IPreferenceStore; 16 | 17 | import com.reprezen.swagedit.Activator; 18 | import com.reprezen.swagedit.core.json.references.JsonReferenceFactory; 19 | import com.reprezen.swagedit.core.json.references.JsonReferenceValidator; 20 | import com.reprezen.swagedit.core.validation.JsonSchemaValidator; 21 | import com.reprezen.swagedit.core.validation.Validator; 22 | import com.reprezen.swagedit.schema.SwaggerSchema; 23 | 24 | public class SwaggerValidator extends Validator { 25 | 26 | public SwaggerValidator(IPreferenceStore preferenceStore) { 27 | super(preferenceStore); 28 | } 29 | 30 | private JsonReferenceValidator referenceValidator; 31 | private JsonSchemaValidator schemaValidator; 32 | 33 | @Override 34 | public JsonReferenceValidator getReferenceValidator() { 35 | if (referenceValidator == null) { 36 | referenceValidator = new JsonReferenceValidator(getSchemaValidator(), new JsonReferenceFactory()); 37 | } 38 | return referenceValidator; 39 | } 40 | 41 | @Override 42 | public JsonSchemaValidator getSchemaValidator() { 43 | if (schemaValidator == null) { 44 | schemaValidator = new SwaggerSchemaValidator(); 45 | } 46 | return schemaValidator; 47 | } 48 | 49 | public static class SwaggerSchemaValidator extends JsonSchemaValidator { 50 | 51 | public static final SwaggerSchema schema = Activator.getDefault() != null ? // 52 | Activator.getDefault().getSchema() : new SwaggerSchema(); 53 | 54 | public SwaggerSchemaValidator() { 55 | super(schema.asJson(), new HashMap<>()); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/wizards/SwagEditNewWizard.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.wizards; 12 | 13 | import org.eclipse.jface.viewers.IStructuredSelection; 14 | import org.eclipse.ui.dialogs.WizardNewFileCreationPage; 15 | 16 | import com.reprezen.swagedit.core.wizard.NewFileWizard; 17 | import com.reprezen.swagedit.editor.SwaggerEditor; 18 | 19 | public class SwagEditNewWizard extends NewFileWizard { 20 | 21 | @Override 22 | protected WizardNewFileCreationPage newFileCreationPage(IStructuredSelection selection) { 23 | return new SwagEditNewWizardPage(selection); 24 | } 25 | 26 | public SwagEditNewWizard() { 27 | super(SwaggerEditor.ID); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /com.reprezen.swagedit/src/com/reprezen/swagedit/wizards/SwagEditNewWizardPage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2016 ModelSolv, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * ModelSolv, Inc. - initial API and implementation and/or initial documentation 10 | *******************************************************************************/ 11 | package com.reprezen.swagedit.wizards; 12 | 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | 16 | import org.eclipse.jface.viewers.IStructuredSelection; 17 | import org.eclipse.ui.dialogs.WizardNewFileCreationPage; 18 | 19 | import com.reprezen.swagedit.Activator; 20 | import com.reprezen.swagedit.Messages; 21 | 22 | public class SwagEditNewWizardPage extends WizardNewFileCreationPage { 23 | 24 | private final String extension = "yaml"; 25 | 26 | /** 27 | * Constructor for SwagEditNewWizardPage. 28 | * 29 | * @param selection 30 | */ 31 | public SwagEditNewWizardPage(IStructuredSelection selection) { 32 | super("SwagEditNewWizardPage", selection); 33 | setTitle(Messages.swagedit_wizard_title); 34 | setDescription(Messages.swagedit_wizard_description); 35 | setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/swagger_64.png")); 36 | setFileExtension(extension); 37 | } 38 | 39 | @Override 40 | protected InputStream getInitialContents() { 41 | try { 42 | return Activator.getDefault().getBundle().getEntry("/resources/default.yaml").openStream(); 43 | } catch (IOException e) { 44 | return null; 45 | } 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /etc/img/ContentAssistQuickOutline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/etc/img/ContentAssistQuickOutline.png -------------------------------------------------------------------------------- /etc/img/MacOS File New OpenAI 3 Crop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/etc/img/MacOS File New OpenAI 3 Crop.png -------------------------------------------------------------------------------- /etc/img/SwagEdit Graphics.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/etc/img/SwagEdit Graphics.pptx -------------------------------------------------------------------------------- /etc/img/btn-install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RepreZen/KaiZen-OpenAPI-Editor/7c199211d432c4bbd8915f26791282546fa750e5/etc/img/btn-install.png --------------------------------------------------------------------------------