<commit_before>/*******************************************************************************
 * Copyright (c) 2016 ModelSolv, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    ModelSolv, Inc. - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.reprezen.swagedit.openapi3.assist;

import com.fasterxml.jackson.core.JsonPointer;
import com.google.common.collect.Lists;
import com.reprezen.swagedit.core.assist.JsonReferenceProposalProvider;
import com.reprezen.swagedit.core.assist.contexts.ComponentContextType;
import com.reprezen.swagedit.core.assist.contexts.ContextType;
import com.reprezen.swagedit.core.assist.contexts.ContextTypeCollection;
import com.reprezen.swagedit.core.model.Model;
import com.reprezen.swagedit.core.schema.CompositeSchema;
import com.reprezen.swagedit.openapi3.Activator;
import com.reprezen.swagedit.openapi3.assist.contexts.OperationContextType;
import com.reprezen.swagedit.openapi3.assist.contexts.OperationIdContextType;
import com.reprezen.swagedit.openapi3.assist.contexts.SecuritySchemeContextType;
import com.reprezen.swagedit.openapi3.editor.OpenApi3ContentDescriber;

public class OpenApi3ReferenceProposalProvider extends JsonReferenceProposalProvider {

    public OpenApi3ReferenceProposalProvider() {
        super(new OpenApi3ContextTypeCollection(Activator.getDefault().getSchema()), OpenApi3ContentDescriber.CONTENT_TYPE_ID);
    }

    protected static final String COMPONENT_NAME_REGEX = "[\\w\\.\\-]+";

    protected static final String SCHEMA_COMPONENT_REGEX = "^/components/schemas/(\\w+/)+";
    protected static final String INLINE_SCHEMA_REGEX = ".*schema/(\\w+/)*";
    protected static final String LINK_OPERATIONID_REGEX = ".*/links/" + COMPONENT_NAME_REGEX + "/operationId";
    protected static final String LINK_OPERATIONREF_REGEX = ".*/links/" + COMPONENT_NAME_REGEX + "/operationRef";
    protected static final String SCHEMA_EXAMPLE_REGEX = SCHEMA_COMPONENT_REGEX + "example/\\$ref" + "|"
            + INLINE_SCHEMA_REGEX + "example/\\$ref";
    protected static final String SECURITY_REGEX = ".*/security/\\d+";

    public static final ContextType PATH_LINK_OPERATION_ID = new ContextType("components/links/", "operationId",
            ".*/callbacks/" + COMPONENT_NAME_REGEX + "/\\$ref");

    public static class OpenApi3ContextTypeCollection extends ContextTypeCollection {

        protected OpenApi3ContextTypeCollection(CompositeSchema schema) {
            super(Lists.newArrayList( //
                    // SCHEMA_EXAMPLE, // should go before schema definition
                    new ComponentContextType("components/schemas", "schemas", "schemaOrReference"), //
                    new ComponentContextType("components/parameters", "parameters", "parameterOrReference"), //
                    new ComponentContextType("components/responses", "responses", "responseOrReference"), //
                    new ComponentContextType("components/requestBodies", "requestBody", "requestBodyOrReference"), //
                    new ComponentContextType("components/links", "link", "linkOrReference"), //
                    new ComponentContextType("components/examples", "examples", "exampleOrReference"), //
                    new ComponentContextType("components/headers", "header", "headerOrReference"), //
                    new ComponentContextType("components/callbacks", "callback", "callbackOrReference"), //
                    new ComponentContextType("paths", "path items", "pathItem") {
                        
                        @Override
                        protected String getReferencePointerString() {
                            return "/definitions/pathItem/properties/$ref";
                        }
                    }, //
                    new SecuritySchemeContextType(schema, OpenApi3ReferenceProposalProvider.SECURITY_REGEX), //
                    new OperationIdContextType(schema, OpenApi3ReferenceProposalProvider.LINK_OPERATIONID_REGEX), //
                    new OperationContextType(schema, OpenApi3ReferenceProposalProvider.LINK_OPERATIONREF_REGEX)));
        }

    }

}<commit_msg>#289 - inline constants<commit_after>/*******************************************************************************
 * Copyright (c) 2016 ModelSolv, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    ModelSolv, Inc. - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.reprezen.swagedit.openapi3.assist;

import com.google.common.collect.Lists;
import com.reprezen.swagedit.core.assist.JsonReferenceProposalProvider;
import com.reprezen.swagedit.core.assist.contexts.ComponentContextType;
import com.reprezen.swagedit.core.assist.contexts.ContextTypeCollection;
import com.reprezen.swagedit.core.schema.CompositeSchema;
import com.reprezen.swagedit.openapi3.Activator;
import com.reprezen.swagedit.openapi3.assist.contexts.OperationContextType;
import com.reprezen.swagedit.openapi3.assist.contexts.OperationIdContextType;
import com.reprezen.swagedit.openapi3.assist.contexts.SecuritySchemeContextType;
import com.reprezen.swagedit.openapi3.editor.OpenApi3ContentDescriber;

public class OpenApi3ReferenceProposalProvider extends JsonReferenceProposalProvider {

    public OpenApi3ReferenceProposalProvider() {
        super(new OpenApi3ContextTypeCollection(Activator.getDefault().getSchema()), OpenApi3ContentDescriber.CONTENT_TYPE_ID);
    }

    private static final String COMPONENT_NAME_REGEX = "[\\w\\.\\-]+";
   
    public static class OpenApi3ContextTypeCollection extends ContextTypeCollection {

        protected OpenApi3ContextTypeCollection(CompositeSchema schema) {
            super(Lists.newArrayList( //
                    // SCHEMA_EXAMPLE, // 
                    new ComponentContextType("components/schemas", "schemas", "schemaOrReference"), //
                    new ComponentContextType("components/parameters", "parameters", "parameterOrReference"), //
                    new ComponentContextType("components/responses", "responses", "responseOrReference"), //
                    new ComponentContextType("components/requestBodies", "requestBody", "requestBodyOrReference"), //
                    new ComponentContextType("components/links", "link", "linkOrReference"), //
                    new ComponentContextType("components/examples", "examples", "exampleOrReference"), //
                    new ComponentContextType("components/headers", "header", "headerOrReference"), //
                    new ComponentContextType("components/callbacks", "callback", "callbackOrReference"), //
                    new ComponentContextType("paths", "path items", "pathItem") {
                        
                        @Override
                        protected String getReferencePointerString() {
                            return "/definitions/pathItem/properties/$ref";
                        }
                    }, //
                    new SecuritySchemeContextType(schema, ".*/security/\\d+"), //
                    new OperationIdContextType(schema, ".*/links/" + OpenApi3ReferenceProposalProvider.COMPONENT_NAME_REGEX + "/operationId"), //
                    new OperationContextType(schema, ".*/links/" + OpenApi3ReferenceProposalProvider.COMPONENT_NAME_REGEX + "/operationRef")));
        }

    }

}
{'fraction_non_alphanumeric': 0.13926280035224556, 'fraction_numerical': 0.00629009938357026, 'mean_word_length': 3.39469320066335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4829638', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1975, 'n_words': 369}